Message Listener Container Configuration
有很多选择用于配置与事务和服务质量相关的 SimpleMessageListenerContainer
(SMLC)和 DirectMessageListenerContainer
(DMLC),并且一些选择会相互作用。应用于 SMLC、DMLC 或 StreamListenerContainer
(StLC)的属性(请参见 Using the RabbitMQ Stream Plugin)由相应列中的复选标记表示。请参见 Choosing a Container,以获取帮助您确定哪个容器适合您的应用程序的信息。
There are quite a few options for configuring a SimpleMessageListenerContainer
(SMLC) and a DirectMessageListenerContainer
(DMLC) related to transactions and quality of service, and some of them interact with each other.
Properties that apply to the SMLC, DMLC, or StreamListenerContainer
(StLC) (see Using the RabbitMQ Stream Plugin) are indicated by the check mark in the appropriate column.
See Choosing a Container for information to help you decide which container is appropriate for your application.
下表显示了容器属性名称及其等效属性名称(括号内),其中使用命名空间配置 <rabbit:listener-container/>
时。该元素上的 type
属性可以是 simple
(默认)或 direct
,分别指定 SMLC
或 DMLC
。命名空间不公开某些属性。这些属性由属性的 N/A
表示。
The following table shows the container property names and their equivalent attribute names (in parentheses) when using the namespace to configure a <rabbit:listener-container/>
.
The type
attribute on that element can be simple
(default) or direct
to specify an SMLC
or DMLC
respectively.
Some properties are not exposed by the namespace.
These are indicated by N/A
for the attribute.
Property (Attribute) |
Description |
SMLC |
DMLC |
StLC |
When |
image::tickmark.png[] |
|||
[id="acknowledgeMode"]<<`acknowledgeMode`,acknowledgeMode>> (acknowledge) |
* |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="adviceChain"]<<`adviceChain`,adviceChain>> (advice-chain) |
An array of AOP Advice to apply to the listener execution.
This can be used to apply additional cross-cutting concerns, such as automatic retry in the event of broker death.
Note that simple re-connection after an AMQP error is handled by the |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="afterReceivePostProcessors"]<<`afterReceivePostProcessors`,afterReceivePostProcessors>> (N/A) |
An array of |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="alwaysRequeueWithTxManagerRollback"]<<`alwaysRequeueWithTxManagerRollback`,alwaysRequeueWithTxManagerRollback>> (N/A) |
Set to |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="autoDeclare"]<<`autoDeclare`,autoDeclare>> (auto-declare) |
When set to NOTE: Prior to version 1.6, if there was more than one admin in the context, the container would randomly select one.
If there were no admins, it would create one internally.
In either case, this could cause unexpected results.
Starting with version 1.6, for |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="autoStartup"]<<`autoStartup`,autoStartup>> (auto-startup) |
Flag to indicate that the container should start when the |
image::tickmark.png[] |
image::tickmark.png[] |
image::tickmark.png[] |
[id="batchSize"]<<`batchSize`,batchSize>> (transaction-size) (batch-size) |
When used with |
image::tickmark.png[] |
||
[id="batchingStrategy"]<<`batchingStrategy`,batchingStrategy>> (N/A) |
The strategy used when debatchng messages.
Default |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="channelTransacted"]<<`channelTransacted`,channelTransacted>> (channel-transacted) |
Boolean flag to signal that all messages should be acknowledged in a transaction (either manually or automatically). |
image::tickmark.png[] |
image::tickmark.png[] |
|
|
image::tickmark.png[] |
|||
[id="concurrentConsumers"]<<`concurrentConsumers`,concurrentConsumers>> (concurrency) |
The number of concurrent consumers to initially start for each listener.
See Listener Concurrency.
For the |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="connectionFactory"]<<`connectionFactory`,connectionFactory>> (connection-factory) |
A reference to the |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="consecutiveActiveTrigger"]<<`consecutiveActiveTrigger`,consecutiveActiveTrigger>> (min-consecutive-active) |
The minimum number of consecutive messages received by a consumer, without a receive timeout occurring, when considering starting a new consumer. Also impacted by 'batchSize'. See Listener Concurrency. Default: 10. |
image::tickmark.png[] |
||
[id="consecutiveIdleTrigger"]<<`consecutiveIdleTrigger`,consecutiveIdleTrigger>> (min-consecutive-idle) |
The minimum number of receive timeouts a consumer must experience before considering stopping a consumer. Also impacted by 'batchSize'. See Listener Concurrency. Default: 10. |
image::tickmark.png[] |
||
[id="consumerBatchEnabled"]<<`consumerBatchEnabled`,consumerBatchEnabled>> (batch-enabled) |
If the |
image::tickmark.png[] |
||
[id="consumerCustomizer"]<<`consumerCustomizer`,consumerCustomizer>> (N/A) |
A |
image::tickmark.png[] |
||
[id="consumerStartTimeout"]<<`consumerStartTimeout`,consumerStartTimeout>> (N/A) |
The time in milliseconds to wait for a consumer thread to start.
If this time elapses, an error log is written.
An example of when this might happen is if a configured See Threading and Asynchronous Consumers. Default: 60000 (one minute). |
image::tickmark.png[] |
||
[id="consumerTagStrategy"]<<`consumerTagStrategy`,consumerTagStrategy>> (consumer-tag-strategy) |
Set an implementation of ConsumerTagStrategy, enabling the creation of a (unique) tag for each consumer. |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="consumersPerQueue"]<<`consumersPerQueue`,consumersPerQueue>> (consumers-per-queue) |
The number of consumers to create for each configured queue. See Listener Concurrency. |
image::tickmark.png[] |
||
When using the RabbitMQ Sharding Plugin with |
image::tickmark.png[] |
image::tickmark.png[] |
||
[id="debatchingEnabled"]<<`debatchingEnabled`,debatchingEnabled>> (N/A) |
When true, the listener container will debatch batched messages and invoke the listener with each message from the batch.
Starting with version 2.2.7, producer created batches will be debatched as a |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="declarationRetries"]<<`declarationRetries`,declarationRetries>> (declaration-retries) |
The number of retry attempts when passive queue declaration fails. Passive queue declaration occurs when the consumer starts or, when consuming from multiple queues, when not all queues were available during initialization. When none of the configured queues can be passively declared (for any reason) after the retries are exhausted, the container behavior is controlled by the 'missingQueuesFatal` property, described earlier. Default: Three retries (for a total of four attempts). |
image::tickmark.png[] |
||
[id="defaultRequeueRejected"]<<`defaultRequeueRejected`,defaultRequeueRejected>> (requeue-rejected) |
Determines whether messages that are rejected because the listener threw an exception should be requeued or not.
Default: |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="errorHandler"]<<`errorHandler`,errorHandler>> (error-handler) |
A reference to an |
image::tickmark.png[] |
image::tickmark.png[] |
|
Determines whether the single consumer in this container has exclusive access to the queues.
The concurrency of the container must be 1 when this is |
image::tickmark.png[] |
image::tickmark.png[] |
||
[id="exclusiveConsumerExceptionLogger"]<<`exclusiveConsumerExceptionLogger`,exclusiveConsumerExceptionLogger>> (N/A) |
An exception logger used when an exclusive consumer cannot gain access to a queue.
By default, this is logged at the |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="failedDeclarationRetryInterval"]<<`failedDeclarationRetryInterval`,failedDeclarationRetryInterval>> (failed-declaration -retry-interval) |
The interval between passive queue declaration retry attempts. Passive queue declaration occurs when the consumer starts or, when consuming from multiple queues, when not all queues were available during initialization. Default: 5000 (five seconds). |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="forceCloseChannel"]<<`forceCloseChannel`,forceCloseChannel>> (N/A) |
If the consumers do not respond to a shutdown within |
image::tickmark.png[] |
image::tickmark.png[] |
|
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 |
image::tickmark.png[] |
image::tickmark.png[] |
||
When true, the |
image::tickmark.png[] |
image::tickmark.png[] |
||
(group) |
This is available only when using the namespace.
When specified, a bean of type |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="idleEventInterval"]<<`idleEventInterval`,idleEventInterval>> (idle-event-interval) |
image::tickmark.png[] |
image::tickmark.png[] |
||
[id="javaLangErrorHandler"]<<`javaLangErrorHandler`,javaLangErrorHandler>> (N/A) |
An |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="maxConcurrentConsumers"]<<`maxConcurrentConsumers`,maxConcurrentConsumers>> (max-concurrency) |
The maximum number of concurrent consumers to start, if needed, on demand. Must be greater than or equal to 'concurrentConsumers'. See Listener Concurrency. |
image::tickmark.png[] |
||
[id="messagesPerAck"]<<`messagesPerAck`,messagesPerAck>> (N/A) |
The number of messages to receive between acks.
Use this to reduce the number of acks sent to the broker (at the cost of increasing the possibility of redelivered messages).
Generally, you should set this property only on high-volume listener containers.
If this is set and a message is rejected (exception thrown), pending acks are acknowledged and the failed message is rejected.
Not allowed with transacted channels.
If the |
image::tickmark.png[] |
||
[id="mismatchedQueuesFatal"]<<`mismatchedQueuesFatal`,mismatchedQueuesFatal>> (mismatched-queues-fatal) |
When the container starts, if this property is If the problem is detected during recovery (for example, after a lost connection), the container is stopped. There must be a single NOTE: If the broker is not available during initial startup, the container starts and the conditions are checked when the connection is established. IMPORTANT: The check is done against all queues in the context, not just the queues that a particular listener is configured to use.
If you wish to limit the checks to just those queues used by a container, you should configure a separate IMPORTANT: Mismatched queue argument detection is disabled while starting a container for a |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="missingQueuesFatal"]<<`missingQueuesFatal`,missingQueuesFatal>> (missing-queues-fatal) |
When set to This was not configurable in previous versions. When set to You can also use a properties bean to set the property globally for all containers, as follows: [source,xml] ---- <util:properties id="spring.amqp.global.properties"> <prop key="mlc.missing.queues.fatal"> false </prop> </util:properties> ---- This global property is not applied to any containers that have an explicit The default retry properties (three retries at five-second intervals) can be overridden by setting the properties below. IMPORTANT: Missing queue detection is disabled while starting a container for a |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="monitorInterval"]<<`monitorInterval`,monitorInterval>> (monitor-interval) |
With the DMLC, a task is scheduled to run at this interval to monitor the state of the consumers and recover any that have failed. |
image::tickmark.png[] |
||
Set to |
image::tickmark.png[] |
image::tickmark.png[] |
||
When |
image::tickmark.png[] |
image::tickmark.png[] |
||
[id="possibleAuthenticationFailureFatal"]<<`possibleAuthenticationFailureFatal`,possibleAuthenticationFailureFatal>> (possible-authentication-failure-fatal) |
When set to Since version 2.0. DirectMessageListenerContainer When set to SimpleMessageListenerContainer When set to You can also use a properties bean to set the property globally for all containers, as follows: [source,xml] ---- <util:properties id="spring.amqp.global.properties"> <prop key="mlc.possible.authentication.failure.fatal"> false </prop> </util:properties> ---- This global property will not be applied to any containers that have an explicit The default retry properties (3 retries at 5 second intervals) can be overridden using the properties after this one. |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="prefetchCount"]<<`prefetchCount`,prefetchCount>> (prefetch) |
The number of unacknowledged messages that can be outstanding at each consumer.
The higher this value is, the faster the messages can be delivered, but the higher the risk of non-sequential processing.
Ignored if the IMPORTANT: There are scenarios where the prefetch value should be low — for example, with large messages, especially if the processing is slow (messages could add up to a large amount of memory in the client process), and if strict message ordering is necessary (the prefetch value should be set back to 1 in this case). Also, with low-volume messaging and multiple consumers (including concurrency within a single listener container instance), you may wish to reduce the prefetch to get a more even distribution of messages across consumers. Also see |
image::tickmark.png[] |
image::tickmark.png[] |
|
When a listener container listens to at least one auto-delete queue and it is found to be missing during startup, the container uses a |
image::tickmark.png[] |
image::tickmark.png[] |
||
[id="receiveTimeout"]<<`receiveTimeout`,receiveTimeout>> (receive-timeout) |
The maximum time to wait for each message.
If |
image::tickmark.png[] |
||
[id="batchReceiveTimeout"]<<`batchReceiveTimeout`,batchReceiveTimeout>> (batch-receive-timeout) |
The number of milliseconds of timeout for gathering batch messages.
It limits the time to wait to fill batchSize.
When |
image::tickmark.png[] |
||
[id="recoveryBackOff"]<<`recoveryBackOff`,recoveryBackOff>> (recovery-back-off) |
Specifies the |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="recoveryInterval"]<<`recoveryInterval`,recoveryInterval>> (recovery-interval) |
Determines the time in milliseconds between attempts to start a consumer if it fails to start for non-fatal reasons.
Default: 5000.
Mutually exclusive with |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="retryDeclarationInterval"]<<`retryDeclarationInterval`,retryDeclarationInterval>> (missing-queue- retry-interval) |
If a subset of the configured queues are available during consumer initialization, the consumer starts consuming from those queues. The consumer tries to passively declare the missing queues by using this interval. When this interval elapses, the 'declarationRetries' and 'failedDeclarationRetryInterval' is used again. If there are still missing queues, the consumer again waits for this interval before trying again. This process continues indefinitely until all queues are available. Default: 60000 (one minute). |
image::tickmark.png[] |
||
[id="shutdownTimeout"]<<`shutdownTimeout`,shutdownTimeout>> (N/A) |
When a container shuts down (for example,
if its enclosing |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="startConsumerMinInterval"]<<`startConsumerMinInterval`,startConsumerMinInterval>> (min-start-interval) |
The time in milliseconds that must elapse before each new consumer is started on demand. See Listener Concurrency. Default: 10000 (10 seconds). |
image::tickmark.png[] |
||
[id="statefulRetryFatal"]<<`statefulRetryFatal`,statefulRetryFatal>> WithNullMessageId (N/A) |
When using a stateful retry advice, if a message with a missing |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="stopConsumerMinInterval"]<<`stopConsumerMinInterval`,stopConsumerMinInterval>> (min-stop-interval) |
The time in milliseconds that must elapse before a consumer is stopped since the last consumer was stopped when an idle consumer is detected. See Listener Concurrency. Default: 60000 (one minute). |
image::tickmark.png[] |
||
[id="streamConverter"]<<`streamConverter`,streamConverter>> (N/A) |
A |
image::tickmark.png[] |
||
[id="taskExecutor"]<<`taskExecutor`,taskExecutor>> (task-executor) |
A reference to a Spring |
image::tickmark.png[] |
image::tickmark.png[] |
|
[id="taskScheduler"]<<`taskScheduler`,taskScheduler>> (task-scheduler) |
With the DMLC, the scheduler used to run the monitor task at the 'monitorInterval'. |
image::tickmark.png[] |
||
[id="transactionManager"]<<`transactionManager`,transactionManager>> (transaction-manager) |
External transaction manager for the operation of the listener.
Also complementary to |
image::tickmark.png[] |
image::tickmark.png[] |