Configure prefetch and channelPrefetch
masterPrefetch
prefetch limits the number of unacknowledged messages a subscription can have outstanding. This prevents overloading your event loop or downstream services. The default is 10.
Channel Prefetch
channelPrefetch operates at the channel level. Because Rascal uses a dedicated channel per subscriber, this is rarely needed and has higher overhead in clusters. It is primarily used to adjust prefetch dynamically without cancelling the subscription.
Note: When using channelPrefetch, you should set the regular consumer prefetch to 0 to prevent conflicts.
// Dynamically tuning channel prefetch
const subscription = await broker.subscribe('s1', { prefetch: 0, channelPrefetch: 5 });
subscription.on('message', (message, content, ackOrNack) => {
ackOrNack();
const prefetch = tunePrefetch();
await subscription.setChannelPrefetch(prefetch);
});