Changes in 1.6 Since 1.5

  • 为配置队列和交换对象提供流畅 API 的构建器。

  • 支持匿名队列的命名策略。

  • 侦听器容器支持在空闲时发布事件。

  • 默认错误处理程序将无法恢复的异常视为致命问题。

  • 使用 RabbitAdmin 实例时自动声明语义的更改。

  • AmqpTemplate 支持具有超时接收的新方法。

  • 引入 AsyncRabbitTemplate 以异步发送和接收消息。

Testing Support

现在提供了一个新的测试支持库。有关更多信息,请参阅 Testing Support

A new testing support library is now provided. See Testing Support for more information.

Builder

现在提供了针对 `Queue`和 `Exchange`对象提供流畅 API 的构建器。有关更多信息,请参见 Builder API for Queues and Exchanges

Builders that provide a fluent API for configuring Queue and Exchange objects are now available. See Builder API for Queues and Exchanges for more information.

Namespace Changes

Connection Factory

现在可以将 `thread-factory`添加到连接工厂 bean 声明中——例如,为 `amqp-client`库创建的线程命名。有关更多信息,请参阅 Connection and Resource Management

You can now add a thread-factory to a connection factory bean declaration — for example, to name the threads created by the amqp-client library. See Connection and Resource Management for more information.

当使用 `CacheMode.CONNECTION`时,现在可以限制允许的最大连接数。有关更多信息,请参阅 Connection and Resource Management

When you use CacheMode.CONNECTION, you can now limit the total number of connections allowed. See Connection and Resource Management for more information.

Queue Definitions

现在,您可以提供匿名队列的命名策略。有关更多信息,请参见 AnonymousQueue

You can now provide a naming strategy for anonymous queues. See AnonymousQueue for more information.

Listener Container Changes

Idle Message Listener Detection

现在可以配置监听容器,以便在空闲时发布 `ApplicationEvent`实例。有关更多信息,请参阅 Detecting Idle Asynchronous Consumers

You can now configure listener containers to publish ApplicationEvent instances when idle. See Detecting Idle Asynchronous Consumers for more information.

Mismatched Queue Detection

默认情况下,当监听容器启动时,如果检测到具有不匹配属性或参数的队列,容器将记录异常,但继续监听。容器现在有一个名为 `mismatchedQueuesFatal`的属性,如果在启动过程中检测到该问题,则该属性将阻止容器(和上下文)启动。如果在之后检测到该问题(例如在从连接故障中恢复后),它也会停止容器。有关更多信息,请参阅 Message Listener Container Configuration

By default, when a listener container starts, if queues with mismatched properties or arguments are detected, the container logs the exception but continues to listen. The container now has a property called mismatchedQueuesFatal, which prevents the container (and context) from starting if the problem is detected during startup. It also stops the container if the problem is detected later, such as after recovering from a connection failure. See Message Listener Container Configuration for more information.

Listener Container Logging

现在,侦听器容器将它的 beanName 作为 threadNamePrefix 提供给内部 SimpleAsyncTaskExecutor。这有助于日志分析。

Now, listener container provides its beanName to the internal SimpleAsyncTaskExecutor as a threadNamePrefix. It is useful for logs analysis.

Default Error Handler

默认错误处理程序 (ConditionalRejectingErrorHandler) 现在将无法恢复的 `@RabbitListener`异常视为致命错误。有关更多信息,请参阅 Exception Handling

The default error handler (ConditionalRejectingErrorHandler) now considers irrecoverable @RabbitListener exceptions as fatal. See Exception Handling for more information.

AutoDeclare and RabbitAdmin Instances

有关该选项的语义在应用程序上下文中使用 RabbitAdmin`实例方面的一些更改,请参阅 Message Listener Container Configuration(`autoDeclare)。

See Message Listener Container Configuration (autoDeclare) for some changes to the semantics of that option with respect to the use of RabbitAdmin instances in the application context.

AmqpTemplate: Receive with Timeout

引入了许多新的具有 `timeout`的 `receive()`方法,用于 `AmqpTemplate`及其 `RabbitTemplate`实现。有关更多信息,请参阅 Polling Consumer

A number of new receive() methods with timeout have been introduced for the AmqpTemplate and its RabbitTemplate implementation. See Polling Consumer for more information.

Using AsyncRabbitTemplate

已经引入了一个新的 AsyncRabbitTemplate。此模板提供了许多发送和接收方法,其中返回值是 ListenableFuture,可用于稍后以同步或异步方式获取结果。有关更多信息,请参见 Async Rabbit Template

A new AsyncRabbitTemplate has been introduced. This template provides a number of send and receive methods, where the return value is a ListenableFuture, which can be used later to obtain the result either synchronously or asynchronously. See Async Rabbit Template for more information.

RabbitTemplate Changes

1.4.1 引入了在代理支持的情况下使用 direct reply-to的能力。它比为每个回复使用临时队列更高效。这个版本允许您覆盖此默认行为并通过将 `useTemporaryReplyQueues`属性设置为 `true`来使用临时队列。有关更多信息,请参见 RabbitMQ Direct reply-to

1.4.1 introduced the ability to use direct reply-to when the broker supports it. It is more efficient than using a temporary queue for each reply. This version lets you override this default behavior and use a temporary queue by setting the useTemporaryReplyQueues property to true. See RabbitMQ Direct reply-to for more information.

RabbitTemplate`现在支持`user-id-expression(在使用 Java 配置时的 userIdExpression)。有关详细信息,请参见 Validated User-ID RabbitMQ documentationValidated User Id

The RabbitTemplate now supports a user-id-expression (userIdExpression when using Java configuration). See Validated User-ID RabbitMQ documentation and Validated User Id for more information.

Message Properties

Using CorrelationId

correlationId`消息属性现在可以是`String。有关详细信息,请参见 Message Properties Converters

The correlationId message property can now be a String. See Message Properties Converters for more information.

Long String Headers

以前,DefaultMessagePropertiesConverter 将超过长字符串限制(默认 1024)的标头“converted”为 DataInputStream(实际上,它引用了 LongString 实例的 DataInputStream)。在输出时,此标头未转换(除非是为 String —— 例如通过在流上调用 toString(),将 java.io.DataInputStream@1d057a39 转换为 string)。

Previously, the DefaultMessagePropertiesConverter “converted” headers longer than the long string limit (default 1024) to a DataInputStream (actually, it referenced the LongString instance’s DataInputStream). On output, this header was not converted (except to a String — for example, java.io.DataInputStream@1d057a39 by calling toString() on the stream).

在此版本中,较大的 LongString 实例现在默认情况下保留为 LongString 实例。您可以使用 getBytes[]toString()getStream() 方法访问内容。现在,较大的传入 LongString 在输出时也正确地 “converted”。

With this release, long LongString instances are now left as LongString instances by default. You can access the contents by using the getBytes[], toString(), or getStream() methods. A large incoming LongString is now correctly “converted” on output too.

有关详细信息,请参见 Message Properties Converters

See Message Properties Converters for more information.

Inbound Delivery Mode

deliveryMode 属性不再映射到 MessageProperties.deliveryMode。如果将相同的 MessageProperties 对象用于发送出站消息,此更改可避免意外传播。而是将入站 deliveryMode 标头映射到 MessageProperties.receivedDeliveryMode

The deliveryMode property is no longer mapped to the MessageProperties.deliveryMode. This change avoids unintended propagation if the the same MessageProperties object is used to send an outbound message. Instead, the inbound deliveryMode header is mapped to MessageProperties.receivedDeliveryMode.

有关详细信息,请参见 Message Properties Converters

See Message Properties Converters for more information.

在使用带注释的端点时,在名为 AmqpHeaders.RECEIVED_DELIVERY_MODE 的标头中提供标头。

When using annotated endpoints, the header is provided in the header named AmqpHeaders.RECEIVED_DELIVERY_MODE.

有关更多信息,请参阅 Annotated Endpoint Method Signature

See Annotated Endpoint Method Signature for more information.

Inbound User ID

user_id 属性不再映射到 MessageProperties.userId。如果将相同的 MessageProperties 对象用于发送出站消息,此更改可避免意外传播。而是将入站 userId 标头映射到 MessageProperties.receivedUserId

The user_id property is no longer mapped to the MessageProperties.userId. This change avoids unintended propagation if the the same MessageProperties object is used to send an outbound message. Instead, the inbound userId header is mapped to MessageProperties.receivedUserId.

有关详细信息,请参见 Message Properties Converters

See Message Properties Converters for more information.

在使用带注释的端点时,在名为 AmqpHeaders.RECEIVED_USER_ID 的标头中提供标头。

When you use annotated endpoints, the header is provided in the header named AmqpHeaders.RECEIVED_USER_ID.

有关更多信息,请参阅 Annotated Endpoint Method Signature

See Annotated Endpoint Method Signature for more information.

RabbitAdmin Changes

Declaration Failures

以前,ignoreDeclarationFailures 标志仅对频道的 IOException 产生影响(例如错误匹配的参数)。现在,它对任何异常都有效(例如 TimeoutException)。此外,现在只要声明失败,就会发布 DeclarationExceptionEventRabbitAdmin 上一个声明事件也可以作为属性 lastDeclarationExceptionEvent 获取。有关更多信息,请参阅 Configuring the Broker

Previously, the ignoreDeclarationFailures flag took effect only for IOException on the channel (such as mis-matched arguments). It now takes effect for any exception (such as TimeoutException). In addition, a DeclarationExceptionEvent is now published whenever a declaration fails. The RabbitAdmin last declaration event is also available as a property lastDeclarationExceptionEvent. See Configuring the Broker for more information.

@RabbitListener Changes

Multiple Containers for Each Bean

如果您使用 Java 8 或更高版本,现在可以将多个 @RabbitListener 注释添加到 @Bean 类或其方法中。在使用 Java 7 或更早版本时,您可以使用 @RabbitListeners 容器注释来提供相同的功能。有关更多信息,请参阅 @Repeatable @RabbitListener

When you use Java 8 or later, you can now add multiple @RabbitListener annotations to @Bean classes or their methods. When using Java 7 or earlier, you can use the @RabbitListeners container annotation to provide the same functionality. See @Repeatable @RabbitListener for more information.

@SendTo SpEL Expressions

没有 replyTo 属性的路由回复的 @SendTo 现在可以是针对请求或回复计算的 SpEL 表达式。有关更多信息,请参阅 Reply Management

@SendTo for routing replies with no replyTo property can now be SpEL expressions evaluated against the request/reply. See Reply Management for more information.

@QueueBinding Improvements

现在,您可以在 @QueueBinding 注释中指定队列、交换和绑定的参数。现在,@QueueBinding 支持标头交换。有关更多信息,请参阅 Annotation-driven Listener Endpoints

You can now specify arguments for queues, exchanges, and bindings in @QueueBinding annotations. Header exchanges are now supported by @QueueBinding. See Annotation-driven Listener Endpoints for more information.

Delayed Message Exchange

Spring AMQP 现在对 RabbitMQ Delayed Message Exchange 插件提供了重要的支持。有关更多信息,请参阅 Delayed Message Exchange

Spring AMQP now has first class support for the RabbitMQ Delayed Message Exchange plugin. See Delayed Message Exchange for more information.

Exchange Internal Flag

现在,任何 Exchange 定义都可以标记为 internal,并且 RabbitAdmin 在声明交换时将该值传递给代理。有关更多信息,请参阅 Configuring the Broker

Any Exchange definitions can now be marked as internal, and RabbitAdmin passes the value to the broker when declaring the exchange. See Configuring the Broker for more information.

CachingConnectionFactory Changes

CachingConnectionFactory Cache Statistics

`CachingConnectionFactory`现在在运行时和 JMX 中提供缓存属性。有关详细信息,请参见 Runtime Cache Properties

The CachingConnectionFactory now provides cache properties at runtime and over JMX. See Runtime Cache Properties for more information.

Accessing the Underlying RabbitMQ Connection Factory

现在添加了新的 getter 以提供对底层工厂的访问权限。例如,您可以使用此 getter 添加自定义的连接属性。有关更多信息,请参阅 Adding Custom Client Connection Properties

A new getter has been added to provide access to the underlying factory. You can use this getter, for example, to add custom connection properties. See Adding Custom Client Connection Properties for more information.

Channel Cache

默认的频道缓存大小已从 1 增加到 25。有关更多信息,请参阅 Connection and Resource Management

The default channel cache size has been increased from 1 to 25. See Connection and Resource Management for more information.

此外,SimpleMessageListenerContainer 不再调整缓存大小以至少与 concurrentConsumers 的数量一样大,这是多余的,因为容器客户机通道从未被缓存。

In addition, the SimpleMessageListenerContainer no longer adjusts the cache size to be at least as large as the number of concurrentConsumers — this was superfluous, since the container consumer channels are never cached.

Using RabbitConnectionFactoryBean

现在,工厂 bean 公开了一个属性,用于向生成的工厂连接添加客户端连接属性。

The factory bean now exposes a property to add client connection properties to connections made by the resulting factory.

Java Deserialization

现在,在使用 Java 反序列化时,您可以配置允许类别的“允许列表”。如果您接受来自不受信任源的包含序列化 Java 对象的消息,则应考虑创建允许列表。有关详细信息,请参阅 Java Deserialization

You can now configure a “allowed list” of allowable classes when you use Java deserialization. You should consider creating an allowed list if you accept messages with serialized java objects from untrusted sources. See Java Deserialization for more information.

JSON MessageConverter

JSON 消息转换器的改进现在允许使用不具有消息头中类型信息的邮件。有关更多信息,请参阅 Message Conversion for Annotated Methods[json-message-converter]

Improvements to the JSON message converter now allow the consumption of messages that do not have type information in message headers. See Message Conversion for Annotated Methods and [json-message-converter] for more information.

Logging Appenders

Log4j 2

已添加一个 log4j 2 附加设备,现在可以使用 addresses 属性将附加设备配置为连接到代理程序集群。

A log4j 2 appender has been added, and the appenders can now be configured with an addresses property to connect to a broker cluster.

Client Connection Properties

现在,您可以将自定义客户端连接属性添加到 RabbitMQ 连接中。

You can now add custom client connection properties to RabbitMQ connections.

有关更多信息,请参见Logging Subsystem AMQP Appenders

See Logging Subsystem AMQP Appenders for more information.