For the latest stable version, please use Spring AMQP 3.2.1!

Changes in 2.0 Since 1.7

Using CachingConnectionFactory

Starting with version 2.0.2, you can configure the RabbitTemplate to use a different connection to that used by listener containers. This change avoids deadlocked consumers when producers are blocked for any reason. See Using a Separate Connection for more information.

AMQP Client library

Spring AMQP now uses the new 5.0.x version of the amqp-client library provided by the RabbitMQ team. This client has auto recovery configured by default. See RabbitMQ Automatic Connection/Topology recovery.

As of version 4.0, the client enables automatic recovery by default. While compatible with this feature, Spring AMQP has its own recovery mechanisms, and the client recovery feature generally is not needed. We recommend that you disable amqp-client automatic recovery, to avoid getting AutoRecoverConnectionNotCurrentlyOpenException instances when the broker is available but the connection has not yet recovered. Starting with version 1.7.1, Spring AMQP disables it unless you explicitly create your own RabbitMQ connection factory and provide it to the CachingConnectionFactory. RabbitMQ ConnectionFactory instances created by the RabbitConnectionFactoryBean also have the option disabled by default.

General Changes

The ExchangeBuilder now builds durable exchanges by default. The @Exchange annotation used within a @QeueueBinding also declares durable exchanges by default. The @Queue annotation used within a @RabbitListener by default declares durable queues if named and non-durable if anonymous. See Builder API for Queues and Exchanges and Annotation-driven Listener Endpoints for more information.

Deleted Classes

UniquelyNameQueue is no longer provided. It is unusual to create a durable non-auto-delete queue with a unique name. This class has been deleted. If you require its functionality, use new Queue(UUID.randomUUID().toString()).

New Listener Container

The DirectMessageListenerContainer has been added alongside the existing SimpleMessageListenerContainer. See Choosing a Container and Message Listener Container Configuration for information about choosing which container to use as well as how to configure them.

Log4j Appender

This appender is no longer available due to the end-of-life of log4j. See Logging Subsystem AMQP Appenders for information about the available log appenders.

RabbitTemplate Changes

Previously, a non-transactional RabbitTemplate participated in an existing transaction if it ran on a transactional listener container thread. This was a serious bug. However, users might have relied on this behavior. Starting with version 1.6.2, you must set the channelTransacted boolean on the template for it to participate in the container transaction.

The RabbitTemplate now uses a DirectReplyToMessageListenerContainer (by default) instead of creating a new consumer for each request. See RabbitMQ Direct reply-to for more information.

The AsyncRabbitTemplate now supports direct reply-to. See Async Rabbit Template for more information.

The RabbitTemplate and AsyncRabbitTemplate now have receiveAndConvert and convertSendAndReceiveAsType methods that take a ParameterizedTypeReference<T> argument, letting the caller specify the type to which to convert the result. This is particularly useful for complex types or when type information is not conveyed in message headers. It requires a SmartMessageConverter such as the Jackson2JsonMessageConverter. See Request/Reply Messaging, Async Rabbit Template, Converting From a Message With RabbitTemplate, and [json-complex] for more information.

You can now use a RabbitTemplate to perform multiple operations on a dedicated channel. See Scoped Operations for more information.

Listener Adapter

A convenient FunctionalInterface is available for using lambdas with the MessageListenerAdapter. See MessageListenerAdapter for more information.

Listener Container Changes

Prefetch Default Value

The prefetch default value used to be 1, which could lead to under-utilization of efficient consumers. The default prefetch value is now 250, which should keep consumers busy in most common scenarios and, thus, improve throughput.

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.

For more background about prefetch, see this post about consumer utilization in RabbitMQ and this post about queuing theory.

Message Count

Previously, MessageProperties.getMessageCount() returned 0 for messages emitted by the container. This property applies only when you use basicGet (for example, from RabbitTemplate.receive() methods) and is now initialized to null for container messages.

Transaction Rollback Behavior

Message re-queue on transaction rollback is now consistent, regardless of whether or not a transaction manager is configured. See A note on Rollback of Received Messages for more information.

Shutdown Behavior

If the container threads do not respond to a shutdown within shutdownTimeout, the channels are forced closed by default. See Message Listener Container Configuration for more information.

After Receive Message Post Processors

If a MessagePostProcessor in the afterReceiveMessagePostProcessors property returns null, the message is discarded (and acknowledged if appropriate).

Connection Factory Changes

The connection and channel listener interfaces now provide a mechanism to obtain information about exceptions. See Connection and Channel Listeners and Publishing is Asynchronous — How to Detect Successes and Failures for more information.

A new ConnectionNameStrategy is now provided to populate the application-specific identification of the target RabbitMQ connection from the AbstractConnectionFactory. See Connection and Resource Management for more information.

Retry Changes

The MissingMessageIdAdvice is no longer provided. Its functionality is now built-in. See Failures in Synchronous Operations and Options for Retry for more information.

Anonymous Queue Naming

By default, AnonymousQueues are now named with the default Base64UrlNamingStrategy instead of a simple UUID string. See AnonymousQueue for more information.

@RabbitListener Changes

You can now provide simple queue declarations (bound only to the default exchange) in @RabbitListener annotations. See Annotation-driven Listener Endpoints for more information.

You can now configure @RabbitListener annotations so that any exceptions are returned to the sender. You can also configure a RabbitListenerErrorHandler to handle exceptions. See Handling Exceptions for more information.

You can now bind a queue with multiple routing keys when you use the @QueueBinding annotation. Also @QueueBinding.exchange() now supports custom exchange types and declares durable exchanges by default.

You can now set the concurrency of the listener container at the annotation level rather than having to configure a different container factory for different concurrency settings.

You can now set the autoStartup property of the listener container at the annotation level, overriding the default setting in the container factory.

You can now set after receive and before send (reply) MessagePostProcessor instances in the RabbitListener container factories.

See Annotation-driven Listener Endpoints for more information.

Starting with version 2.0.3, one of the @RabbitHandler annotations on a class-level @RabbitListener can be designated as the default. See Multi-method Listeners for more information.

Container Conditional Rollback

When using an external transaction manager (such as JDBC), rule-based rollback is now supported when you provide the container with a transaction attribute. It is also now more flexible when you use a transaction advice. See Conditional Rollback for more information.

Remove Jackson 1.x support

Deprecated in previous versions, Jackson 1.x converters and related components have now been deleted. You can use similar components based on Jackson 2.x. See JSON Message Converter for more information.

JSON Message Converter

When the TypeId is set to Hashtable for an inbound JSON message, the default conversion type is now LinkedHashMap. Previously, it was Hashtable. To revert to a Hashtable, you can use setDefaultMapType on the DefaultClassMapper.

XML Parsers

When parsing Queue and Exchange XML components, the parsers no longer register the name attribute value as a bean alias if an id attribute is present. See A Note On the id and name Attributes for more information.

Blocked Connection

You can now inject the com.rabbitmq.client.BlockedListener into the org.springframework.amqp.rabbit.connection.Connection object. Also, the ConnectionBlockedEvent and ConnectionUnblockedEvent events are emitted by the ConnectionFactory when the connection is blocked or unblocked by the Broker.

See Connection and Resource Management for more information.