GH-2482: Option for Containers to Stop Immediately

Resolves https://github.com/spring-projects/spring-amqp/issues/2482

`forceStop` means stop after the current record and requeue all prefetched.

Just close the channel - canceling the consumer first causes a race condition which
could allow another exclusive or single-active consumer to start processing while
this container is still running.

Also support async stop on DMLC (previously only available on the SMLC).

**cherry-pick to 2.4.x**
# Conflicts:
#	spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java
#	spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainer.java
This commit is contained in:
Gary Russell
2023-07-12 14:56:48 -04:00
committed by abilan
parent fea608e924
commit b98847cd94
7 changed files with 227 additions and 56 deletions

View File

@@ -3467,6 +3467,10 @@ Starting with version 1.5, you can now assign a `group` to the container on the
This provides a mechanism to get a reference to a subset of containers.
Adding a `group` attribute causes a bean of type `Collection<MessageListenerContainer>` to be registered with the context with the group name.
By default, stopping a container will cancel the consumer and process all prefetched messages before stopping.
Starting with versions 2.4.14, 3.0.6, you can set the <<forceStop>> container property to true to stop immediately after the current message is processed, causing any prefetched messages to be requeued.
This is useful, for example, if exclusive or single-active consumers are being used.
[[receiving-batch]]
===== @RabbitListener with Batching
@@ -6199,6 +6203,18 @@ a|image::images/tickmark.png[]
a|image::images/tickmark.png[]
a|
|[[forceStop]]<<forceStop,`forceStop`>> +
(N/A)
|Set to true to stop (when the container is stopped) after the current record is processed; causing all prefetched messages to be requeued.
By default, the container will cancel the consumer and process all prefetched messages before stopping.
Since versions 2.4.14, 3.0.6
Defaults to `false`.
a|image::images/tickmark.png[]
a|image::images/tickmark.png[]
a|
|[[globalQos]]<<globalQos,`globalQos`>> +
(global-qos)