- Spring的CachingConnectionFactory用于缓存Channel。
- The purpose of the Message class is to encapsulate the body and properties within a single instance so that the API can, in turn, be simpler.
- Confirmed and returned messages are supported by setting the publisherConfirms and publisherReturns properties of the CachingConnectionFactory to 'true'.
- Starting with version 1.3, you can now configure the RabbitTemplate to use a RetryTemplate to help with handling problems with broker connectivity.
- For publisher confirms (also known as publisher acknowledgements), the template requires a CachingConnectionFactory that has its publisherConfirms property set to true.
- For returned messages, the template’s mandatory property must be set to true or the mandatory-expression must evaluate to true for a particular message.
- Basically, the message listener container handles the “active” responsibilities so that the listener callback can remain passive. When configuring the container, you essentially bridge the gap between an AMQP Queue and the MessageListener instance. You must provide a reference to the ConnectionFactory and the queue names or Queue instances from which that listener should consume messages.
- The annotated endpoint infrastructure creates a message listener container behind the scenes for
each
annotated method, by using a RabbitListenerContainerFactory. - With
@RabbitListener
, the queue can be declared and bound automatically, as long as aRabbitAdmin exists in the application context
. - With
@EnableRabbit
,by default, the infrastructure looks for a bean named rabbitListenerContainerFactory as the source for the factory to use to create message listener containers. - With
@RabbitListener
, by default, if an annotated listener method throws an exception, it is thrown to the container and the message are requeued and redelivered, discarded, or routed to a dead letter exchange, depending on the container and broker configuration. Nothing is returned to the sender. - By default, the <rabbit:admin/> declaration automatically looks for beans of type Queue, Exchange, and Binding and declares them to the broker on behalf of the user.
- Containers created for annotations are not registered with the application context. You can obtain a collection of all containers by invoking getListenerContainers() on the RabbitListenerEndpointRegistry bean.
- The only concrete implementation we provide is CachingConnectionFactory, which, by default, establishes a single connection proxy that can be shared by the application. Sharing of the connection is possible since the “unit of work” for messaging with AMQP is actually a “channel”.
- CachingConnectionFactory既能用于cache channel,也能用于cache connection factory。通过设置ConnectionFactory的cacheMode参数可以指定是cache channel还是factory。 each call to createConnection() creates a new connection (or retrieves an idle one from the cache). Closing a connection returns it to the cache。
- RabbitTemplate的retry机制主要用于与broker的连接异常。
- 在使用
@EnableRabbit
时,RabbitListener如果没有配置RabbitListenerContainerFactory,那么它将使用容器中名为rabbitListenerContainerFactory
的RabbitListenerContainerFactory。在使用@RabbitListener
时,RabbitListenerContainerFactory会为每一个endpoint创建一个MessageListenerContainer,但是该MessageListenerContainer并不被注册为Spring bean。 - Spring Boot会自动创建一个名为
rabbitListenerContainerFactory
的SimpleRabbitListenerContainerFactory,因此我们可以不用配置自己的RabbitListenerContainerFactory,除非需要定制化。 - Spring AMQP默认情况下将消息设置成了持久化。
- CachingConnectionFactory默认缓存的Channel数为25。
- 默认情况下,RabbitTemplate和RabbitListenerContainerFactory都使用SimpleMessageConverter序列化消息。
- When defaultReQueueRejected=true,it can be overridden by the listener throwing an
- {@link AmqpRejectAndDontRequeueException}
网友评论