public interface Consumer
Dispatcher
and Subscription
.
This interface unifies the responsibilities that are focused on dealing with slow consumers.
The Dispatcher
and Subscription
deal with the mechanics of their specialized roles.
A slow consumer is defined as a consumer that is not handling messages as quickly as they are arriving. For example,
if the application code doesn't call nextMessage()
often enough on a Subscription.
By default the library will allow a consumer to be a bit slow, at times, by caching messages for it in a queue.
The size of this queue is determined by setPendingLimits()
. When a consumer
maxes out its queue size, either by message count or bytes, the library will start to drop messages.
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_MAX_BYTES
The default number of bytes a consumer will hold before it starts to drop messages.
|
static long |
DEFAULT_MAX_MESSAGES
The default number of messages a consumer will hold before it starts to drop them.
|
Modifier and Type | Method and Description |
---|---|
void |
clearDroppedCount()
Reset the drop count to 0.
|
java.util.concurrent.CompletableFuture<java.lang.Boolean> |
drain(java.time.Duration timeout)
Drain tells the consumer to process in flight, or cached messages, but stop receiving new ones.
|
long |
getDeliveredCount() |
long |
getDroppedCount() |
long |
getPendingByteCount() |
long |
getPendingByteLimit() |
long |
getPendingMessageCount() |
long |
getPendingMessageLimit() |
boolean |
isActive() |
void |
setPendingLimits(long maxMessages,
long maxBytes)
Set limits on the maximum number of messages, or maximum size of messages this consumer
will hold before it starts to drop new messages waiting for the application to drain the queue.
|
static final long DEFAULT_MAX_MESSAGES
static final long DEFAULT_MAX_BYTES
void setPendingLimits(long maxMessages, long maxBytes)
Messages are dropped as they encounter a full queue, which is to say, new messages are dropped rather than old messages. If a queue is 10 deep and fills up, the 11th message is dropped.
Sizes are checked after the fact, so if the max bytes is too small for the first pending message to arrive, it will still be stored, only the next message will fail.
Setting a value to anything less than or equal to 0 will disable this check.
long getPendingMessageLimit()
setPendingLimits
long getPendingByteLimit()
setPendingLimits
long getPendingMessageCount()
setPendingLimits
long getPendingByteCount()
setPendingLimits
long getDeliveredCount()
long getDroppedCount()
clearDroppedCount
.void clearDroppedCount()
boolean isActive()
java.util.concurrent.CompletableFuture<java.lang.Boolean> drain(java.time.Duration timeout) throws java.lang.InterruptedException
timeout
- The time to wait for the drain to succeed, pass 0 to wait
forever. Drain involves moving messages to and from the server
so a very short timeout is not recommended.java.lang.InterruptedException
- if the thread is interrupted