2.4节. Sending Messages中有一段看了好多遍才理解
"A better way of thinking about the exchange and routing key properties is that the explicit method parameters will always override the template's default values. In fact, even if you do not explicitly set those properties on the template, there are always default values in place. In both cases, the default is an empty String, but that is actually a sensible default. As far as the routing key is concerned, it's not always necessary in the first place (e.g. a Fanout Exchange). Furthermore, a Queue may be bound to an Exchange with an empty String. Those are both legitimate scenarios for reliance on the default empty String value for the routing key property of the template. As far as the Exchange name is concerned, the empty String is quite commonly used because the AMQP specification defined the "default Exchange" as having no name. Since all Queues are automatically bound to that default Exchange (which is a Direct Exchange) using their name as the binding value, that second method above can be used for simple point-to-point Messaging to any Queue through the default Exchange. Simple privides the queue name as the "routingKey" - either by providing the method parameter at runtime, or, if you prefer to create a template that will be used for publishing primarily or exclusively to a single Queue, the following is perfectly resonable:"
void send(Message message) throws AmqpException;
void send(String routingKey, Message message) throws AmqpException;
void send(String exchange, String routingKey, Message message) throws AmqpException;
======================================================================
2.5.2节Asynchronous Consumer中有一段示例代码
@Bean
public MessageListenerContainer messageListenerContainer() {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(rabbitConnectionFactory());
container.setQueueName("some.queue");
container.setMessageListener(exampleListener());
return container;
}
我表示哪里都找不到MessageListenerContainer这个类啊?!
======================================================================
事务非常重要,摘录下来:
2.10. Transactions
The Spring Rabbit framework has support for automatic transaction management in the synchronous and asynchronous use cases with a number of different semantics that can be selected declaratively, as is familiar to existing users of Spring transactions. This makes many if not most common messaging patterns very easy to implement.
There are two ways to signal the desired transactions semantics to the framework. In both the RabbitTemplate and SimpleMessageListenerContainer there is a flag channelTransacted which, if true, tells the framework to use a transactional channel and to end all oprations (send or receive) with a commit or rollback depending on the outcome, with an exception signaling a rollback.Another signal is to provide an external transaction with one of Spring's PlatformTransactionManager implementations as a context for the ongoing operation. If there is already a transaction in progress when the framework is sending or receiving a message, and the channelTransacted flag is true, then the commit or rollback of the messaging transaction will be deferred until the end of the current transaction. If the channelTransacted flag is false, then no transaction semantics apply to the messaging operation (it is auto-acked).
The channelTransacted flag is a configuration time setting: it is declared and processed once when the AMQP components are created, ususlly at application startup. The external transaction is more dynamic in priciple because the system responds to the current Thread state at running, but in practice is often also a configuration setting, when the transactions are layered onto an application declaratively.
For synchronous use cases with RabbitTemplate the external transaction is provided by the caller, either declaratively or imperatively according to taste (the usual Spring transaction model). An example of a declarative approach (usually preferred because it is non-invasive), where the template has been configured with channelTransacted=true
2.10.1. A note on Rollback of Received Messages
AMQP transactions only apply to messages and acks sent to the broker, so when there is a rollback of a Spring transaction and a message has been received, what Spring AMQP has to do is not just rollback the transaction, but also manually reject the message (sort of a nack, but that's not what the specification calls it). Such messages (and any that are unacked when a channel is closed or aborts) go to the back of the queue on a Rabbit broker, and this behaviour is not what some users expect, especially if they come from a JMS background, so it's good to be aware of it. Thre re-queuing order is not mandated by the AMQP specification, lbut it makes the broker much more efficient, and also means that if it is under load there is a natural back off before the message can be consumed again.
分享到:
相关推荐
Spring AMQP API(Spring AMQP 开发文档).CHM 官网 Spring AMQP API。Spring AMQP 开发文档。
java rabbitmq spring springAMQP 代码包 project
Spring AMQP 1.5.3版本API
spring amqp 配置实现rabbitmq 路由
spring amqp资源下载
Spring AMQP 2 中文 参考手册 中文文档 中文文档都是由软件翻译,翻译内容未检查校对,文档内容仅供参考。
压缩包包含两部分,spring-amqp为java版的Spring AMQP的实现,spring-amqp-sample为补充版(也可作为快速入门的)
Spring AMQP hello world
一个使用springamqp实现的异步消息队列的股票系统,来自springamqp的官网,对于学习springamqp很有帮助。
Spring AMQP 工作队列 源码
Spring AMQP 是基于 Spring 框架的 AMQP 消息解决方案,提供模板化的发送和接收消息的抽象层,提供基于消息驱动的 POJO。同时有 Java 和 .NET 的版本。
spring-amqp-reference
spring-amqp 相关jar , 最近在学spring amqp是时候找jar找了好长时间,现在找全了,在这分享给大家。
spring-amqp文档.zip
spring amqp rabbit 标签使用
spring-amqp-reference-1.6.1.RELEASE
Spring AMQP实例 以及Spring 配置文件动态注入属性使用实战
spring rabbitmq amqp
spring-amqp,Spring 的消息中间件
Spring AMQP 是基于 Spring 框架的 AMQP 消息解决方案,提供模板化的发送和接收消息的抽象层,提供基于消息驱动的 POJO。同时有 Java 和 .NET 的版本。示例代码:public static void main(final String... args...