Interface MessageConsumer
- All Superinterfaces:
AutoCloseable
-
Method Summary
Modifier and TypeMethodDescriptionlongvoidclose()Stops consuming, letting in-flight deliveries settle.longbooleanStops taking new messages and waits for the ones in hand to finish.longlonginFlight()booleanisPaused()booleanvoidpause()Stops taking new messages, keeping the consumer able to start again.intprefetch()voidprefetch(int prefetch) Changes how many unsettled deliveries this consumer may hold, while it is running.queue()longrejected()voidresume()Starts taking messages again afterpause().longretried()
-
Method Details
-
queue
String queue()- Returns:
- the queue being consumed
-
isRunning
boolean isRunning()- Returns:
- whether it is still receiving deliveries
-
acknowledged
long acknowledged()- Returns:
- how many messages have been acknowledged
-
rejected
long rejected()- Returns:
- how many messages have been rejected after a handler failure
-
duplicates
long duplicates()- Returns:
- how many deliveries were recognised as already handled and acknowledged without running the handler; zero unless an idempotency store is configured
-
retried
long retried()- Returns:
- how many messages have been sent to a retry queue for another attempt
-
deadLettered
long deadLettered()- Returns:
- how many messages have been dead-lettered or parked
-
inFlight
long inFlight()- Returns:
- how many messages this consumer is handling right now. Zero means it can be stopped without manufacturing a redelivery
-
drain
Stops taking new messages and waits for the ones in hand to finish.The difference between this and
close()is what happens to work in progress. Closing cancels the subscription and lets whatever was mid-handler settle however it settles; draining cancels the subscription and then waits, so a consumer being removed finishes its work rather than having it redelivered somewhere else.That matters whenever a handler is not idempotent, and it is the primitive a blue-green deployment needs: drain the old side, then cut over.
- Parameters:
timeout- how long to wait for in-flight messages- Returns:
trueif everything finished,falseif the timeout passed first — in which case the consumer is still stopped, but something is still running
-
prefetch
void prefetch(int prefetch) Changes how many unsettled deliveries this consumer may hold, while it is running.Takes effect for deliveries after the call. Messages already in flight are unaffected, because they have been sent and there is no way to un-send them.
- Parameters:
prefetch- the new limit, at least 1
-
prefetch
int prefetch()- Returns:
- the prefetch currently in force
-
pause
void pause()Stops taking new messages, keeping the consumer able to start again.Different from
drain(java.time.Duration)in intent rather than mechanism: pausing is reversible and does not wait. Messages already being handled finish; nothing new is delivered untilresume().What a maintenance window wants, and what the consuming half of a blue-green cutover wants before it commits to stopping.
-
resume
void resume()Starts taking messages again afterpause(). Does nothing if not paused. -
isPaused
boolean isPaused()- Returns:
- whether this consumer is paused rather than stopped
-
close
void close()Stops consuming, letting in-flight deliveries settle.- Specified by:
closein interfaceAutoCloseable
-