public interface ConsumerFlowStrategy
The broker delivers "chunks" of messages to consumers. A chunk can contain from 1 to several thousands of messages. The broker send chunks as long as the subscription has credits. A client connection can provide credits for a given subscription and the broker will send the corresponding number of chunks (1 credit = 1 chunk).
This credit mechanism avoids overwhelming a consumer with messages. A consumer does not want to provide a credit only when it is done with messages of a chunk, because it will be idle between its credit request and the arrival of the next chunk. The idea is to keep consumers busy as much as possible, without accumulating an in-memory backlog on the client side. There is no ideal solution, it depends on the use cases and several parameters (processing time, network, etc).
This is an experimental API, subject to change.
MessageHandler.Context.processed(),
ConsumerBuilder.flow()| Modifier and Type | Interface and Description |
|---|---|
static interface |
ConsumerFlowStrategy.Context
Chunk context.
|
static class |
ConsumerFlowStrategy.CreditOnChunkArrivalConsumerFlowStrategy
Strategy that provides the specified number of initial credits and a credit on each new chunk.
|
static class |
ConsumerFlowStrategy.MessageCountConsumerFlowStrategy
Strategy that provides the specified number of initial credits and a credit when the specified
ratio of the chunk messages are processed.
|
static interface |
ConsumerFlowStrategy.MessageProcessedCallback
Behavior for
MessageHandler.Context.processed() calls. |
| Modifier and Type | Method and Description |
|---|---|
static ConsumerFlowStrategy |
creditOnChunkArrival()
Strategy that provides 1 initial credit and a credit on each new chunk.
|
static ConsumerFlowStrategy |
creditOnChunkArrival(int initialCredits)
Strategy that provides the specified number of initial credits and a credit on each new chunk.
|
static ConsumerFlowStrategy |
creditOnProcessedMessageCount(int initialCredits,
double ratio)
Strategy that provides the specified number of initial credits and a credit when the specified
ratio of the chunk messages are processed.
|
static ConsumerFlowStrategy |
creditWhenHalfMessagesProcessed()
Strategy that provides 1 initial credit and a credit when half of the chunk messages are
processed.
|
static ConsumerFlowStrategy |
creditWhenHalfMessagesProcessed(int initialCredits)
Strategy that provides the specified number of initial credits and a credit when half of the
chunk messages are processed.
|
int |
initialCredits()
The initial number of credits for a subscription.
|
ConsumerFlowStrategy.MessageProcessedCallback |
start(ConsumerFlowStrategy.Context context)
Return the behavior for
MessageHandler.Context.processed() calls. |
int initialCredits()
It must be greater than 0. Values are usually between 1 and 10.
ConsumerFlowStrategy.MessageProcessedCallback start(ConsumerFlowStrategy.Context context)
MessageHandler.Context.processed() calls.
This method is called for each chunk of messages. Implementations return a callback that
will be called when applications consider a message dealt with and call MessageHandler.Context.processed(). The callback can count messages and provide credits
accordingly.
context - chunk contextstatic ConsumerFlowStrategy creditOnChunkArrival()
Calls to MessageHandler.Context.processed() are ignored.
static ConsumerFlowStrategy creditOnChunkArrival(int initialCredits)
Calls to MessageHandler.Context.processed() are ignored.
initialCredits - number of initial creditsstatic ConsumerFlowStrategy creditWhenHalfMessagesProcessed()
Make sure to call MessageHandler.Context.processed() on every message when using
this strategy, otherwise the broker may stop sending messages to the consumer.
static ConsumerFlowStrategy creditWhenHalfMessagesProcessed(int initialCredits)
Make sure to call MessageHandler.Context.processed() on every message when using
this strategy, otherwise the broker may stop sending messages to the consumer.
initialCredits - number of initial creditsstatic ConsumerFlowStrategy creditOnProcessedMessageCount(int initialCredits, double ratio)
Make sure to call MessageHandler.Context.processed() on every message when using
this strategy, otherwise the broker may stop sending messages to the consumer.
initialCredits - number of initial creditsCopyright © 2024 Broadcom Inc. and/or its subsidiaries. All rights reserved.