Class ConsumerContext
-
- All Implemented Interfaces:
public final class ConsumerContextContext for JetStream consumer operations
Provides access to consumer management and monitoring including:
Consumer information and updates
Pause/resume operations
Monitoring metrics
Example usage:
val consumerCtx = js.consumer("MY_STREAM", "MY_CONSUMER") { durable = "MY_CONSUMER" ackPolicy = AckPolicy.EXPLICIT maxDeliver = 5 }.getOrThrow() // Update the consumer consumerCtx.update { maxDeliver = 10 } // Pause the consumer until it is explicitly resumed consumerCtx.pause() // ...or until a deadline, after which the server resumes it automatically consumerCtx.pause(30.minutes) // Check status val isPaused = consumerCtx.isPaused()
-
-
Field Summary
Fields Modifier and Type Field Description private final StringstreamNameprivate final StringconsumerName
-
Method Summary
Modifier and Type Method Description final StringgetStreamName()Name of the stream this consumer belongs to final StringgetConsumerName()Name of the consumer final Result<ConsumerInfo>getInfo()Get current consumer information final Result<ConsumerInfo>update(Function1<ConsumerConfigBuilder, Unit> block)Update the consumer configurationApplies the configuration block to update consumer settings. final Result<Boolean>delete()Delete the consumerPermanently deletes the consumer. final Result<PauseResponse>pause(Instant until)Pause the consumerTemporarily pauses message delivery to the consumer. final Result<PauseResponse>pause(Duration duration)Pause the consumer for a durationConvenience over pause with an absolute deadline. final Result<Boolean>resume()Resume the consumerResumes message delivery to a paused consumer. final BooleanisPaused()Check if the consumer is currently paused final LongdeliveredCount()Get the count of delivered messages final LongackPendingCount()Get the count of pending acknowledgments final LongwaitingPullCount()Get the count of waiting pull requests (for pull consumers) final LongpendingMessageCount()Get the count of pending messages (messages waiting to be delivered) final BooleanisEphemeral()Check if this consumer is ephemeral (not durable)Ephemeral consumers are automatically cleaned up when they become inactive, while durable consumers persist until explicitly deleted. -
-
Method Detail
-
getStreamName
final String getStreamName()
Name of the stream this consumer belongs to
-
getConsumerName
final String getConsumerName()
Name of the consumer
-
getInfo
final Result<ConsumerInfo> getInfo()
Get current consumer information
- Returns:
Result containing ConsumerInfo on success or exception on failure
-
update
final Result<ConsumerInfo> update(Function1<ConsumerConfigBuilder, Unit> block)
Update the consumer configuration
Applies the configuration block to update consumer settings. Only the properties assigned in the block are changed; everything else keeps the value the server currently holds, including settings natsy's DSL does not model.
Note: Not all properties can be updated after creation. Attempting to change immutable properties will result in an error from the NATS server.
- Parameters:
block- Configuration block with consumer updates- Returns:
Result containing updated ConsumerInfo on success
-
delete
final Result<Boolean> delete()
Delete the consumer
Permanently deletes the consumer. This operation cannot be undone. After deletion, the consumer context should not be used.
- Returns:
Result containing true on successful deletion
-
pause
final Result<PauseResponse> pause(Instant until)
Pause the consumer
Temporarily pauses message delivery to the consumer. Messages will continue to accumulate but won't be delivered until the deadline passes or resume is called.
NATS models pausing purely as a deadline: a
pause_untilthat is absent or already in the past is a resume request on the same endpoint. Passing a non-future until is therefore rejected instead of silently resuming, and "pause until further notice" (the default) is expressed as a far-future deadline that resume clears immediately.- Parameters:
until- when the consumer should automatically resume; must be in the future.- Returns:
Result containing PauseResponse on success — success means the consumer is paused. Fails if until is not in the future, or if the server did not pause the consumer.
-
pause
final Result<PauseResponse> pause(Duration duration)
Pause the consumer for a duration
Convenience over pause with an absolute deadline. Duration.INFINITE pauses until resume is called.
- Parameters:
duration- how long to pause for; must be positive- Returns:
Result containing PauseResponse on success
-
resume
final Result<Boolean> resume()
Resume the consumer
Resumes message delivery to a paused consumer.
- Returns:
Result containing true on successful resume
-
isPaused
final Boolean isPaused()
Check if the consumer is currently paused
- Returns:
true if the consumer is paused, false otherwise
-
deliveredCount
final Long deliveredCount()
Get the count of delivered messages
- Returns:
Number of messages delivered by this consumer
-
ackPendingCount
final Long ackPendingCount()
Get the count of pending acknowledgments
- Returns:
Number of unacknowledged messages
-
waitingPullCount
final Long waitingPullCount()
Get the count of waiting pull requests (for pull consumers)
- Returns:
Number of waiting pull requests
-
pendingMessageCount
final Long pendingMessageCount()
Get the count of pending messages (messages waiting to be delivered)
- Returns:
Number of pending messages
-
isEphemeral
final Boolean isEphemeral()
Check if this consumer is ephemeral (not durable)
Ephemeral consumers are automatically cleaned up when they become inactive, while durable consumers persist until explicitly deleted.
- Returns:
true if the consumer is ephemeral, false if durable
-
-
-
-