Interface ConsumerFlowStrategy
- All Known Implementing Classes:
ConsumerFlowStrategy.CreditOnChunkArrivalConsumerFlowStrategy
,ConsumerFlowStrategy.MessageCountConsumerFlowStrategy
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.
- Since:
- 0.12.0
- See Also:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Chunk context.static class
Strategy that provides the specified number of initial credits and a credit on each new chunk.static class
Strategy that provides the specified number of initial credits and a credit when the specified ratio of the chunk messages are processed.static interface
Behavior forMessageHandler.Context.processed()
calls. -
Method Summary
Modifier and TypeMethodDescriptionstatic ConsumerFlowStrategy
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
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
The initial number of credits for a subscription.start
(ConsumerFlowStrategy.Context context) Return the behavior forMessageHandler.Context.processed()
calls.
-
Method Details
-
initialCredits
int initialCredits()The initial number of credits for a subscription.It must be greater than 0. Values are usually between 1 and 10.
- Returns:
- initial number of credits
-
start
Return the behavior forMessageHandler.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.- Parameters:
context
- chunk context- Returns:
- the message processed callback
-
creditOnChunkArrival
Strategy that provides 1 initial credit and a credit on each new chunk.Calls to
MessageHandler.Context.processed()
are ignored.- Returns:
- flow strategy
-
creditOnChunkArrival
Strategy that provides the specified number of initial credits and a credit on each new chunk.Calls to
MessageHandler.Context.processed()
are ignored.- Parameters:
initialCredits
- number of initial credits- Returns:
- flow strategy
-
creditWhenHalfMessagesProcessed
Strategy that provides 1 initial credit and a credit when half of the chunk messages are processed.Make sure to call
MessageHandler.Context.processed()
on every message when using this strategy, otherwise the broker may stop sending messages to the consumer.- Returns:
- flow strategy
-
creditWhenHalfMessagesProcessed
Strategy that provides the specified number of initial credits and a credit when half of the chunk messages are processed.Make sure to call
MessageHandler.Context.processed()
on every message when using this strategy, otherwise the broker may stop sending messages to the consumer.- Parameters:
initialCredits
- number of initial credits- Returns:
- flow strategy
-
creditOnProcessedMessageCount
Strategy that provides the specified number of initial credits and a credit when the specified ratio of the chunk messages are processed.Make sure to call
MessageHandler.Context.processed()
on every message when using this strategy, otherwise the broker may stop sending messages to the consumer.- Parameters:
initialCredits
- number of initial credits- Returns:
- flow strategy
-