`

[笔记]Spring AMQP Reference Documentation

    博客分类:
  • amqp
 
阅读更多

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 开发文档).CHM 官网 Spring AMQP API。Spring AMQP 开发文档。

    Spring AMQP 1.5.3.RELEASE API

    Spring AMQP 1.5.3.RELEASE API是Spring框架中的一个重要组成部分,专注于RabbitMQ消息中间件的集成。Spring AMQP(Advanced Message Queuing Protocol)允许开发者利用AMQP协议来构建可扩展、高可用的消息驱动系统...

    Spring AMQP 2 中文 参考手册 中文文档

    在信息技术领域,Spring AMQP是Spring框架中用于简化AMQP(Advanced Message Queuing Protocol)消息传递的项目,Spring AMQP 2是该项目的版本2。AMQP是应用层协议,用于在客户端和消息传递代理之间进行通信,适用于...

    java rabbitmq spring springAMQP 代码包 project

    在IT行业中,Java、RabbitMQ、Spring以及Spring AMQP是四个非常重要的技术组件,它们在构建高效、可扩展的企业级应用中起着至关重要的作用。这个“java rabbitmq spring springAMQP 代码包 project”显然是一个综合...

    spring-amqp-reference.pdf

    标题《Spring AMQP Reference》所涵盖的知识点主要围绕Spring框架提供的AMQP(Advanced Message Queuing Protocol)消息传递抽象,以及如何在Java应用中利用Spring AMQP进行消息的发送与接收。以下是详细的知识点...

    spring-amqp文档.zip

    《Spring AMQP:Java消息驱动的强大工具》 在IT行业中,Spring框架因其强大的功能和灵活性而备受推崇,尤其是在企业级应用开发中。Spring AMQP作为Spring框架的一部分,为开发者提供了与Advanced Message Queuing ...

    SpringAMQP-支持使用AMQP的Spring编程模型

    **Spring AMQP:一个强大的消息解决方案** Spring AMQP 是 Spring 框架的一部分,它为开发者提供了使用 Advanced Message Queuing Protocol (AMQP) 进行消息传输的强大支持。AMQP 是一种开放标准,用于在分布式系统...

    spring amqp 配置实现rabbitmq 路由

    在本文中,我们将深入探讨如何使用Spring AMQP配置来实现RabbitMQ的路由。Spring AMQP是Spring框架的一个模块,它提供了与RabbitMQ消息中间件集成的能力,使得在Java应用中处理AMQP(Advanced Message Queuing ...

    spring amqp资源下载

    spring amqp资源下载

    spring-amqp

    **Spring AMQP:Spring 框架中的消息中间件** Spring AMQP 是 Spring 框架的一个重要组件,专门用于简化 RabbitMQ(一种基于 Advanced Message Queuing Protocol (AMQP) 的开源消息代理)的集成。它提供了一种高级...

    Spring AMQP hello world

    Spring AMQP(Advanced Message Queuing Protocol)是Spring框架的一个扩展,用于支持RabbitMQ等AMQP消息代理。在这个“Spring AMQP Hello World”示例中,我们将深入探讨如何使用Spring AMQP来创建一个简单的消息...

    spring-amqp 相关jar

    Spring AMQP 是一个由 Spring Framework 提供的框架,它允许开发者使用 Spring 的编程模型与 RabbitMQ 消息中间件进行交互。RabbitMQ 是一种流行的开源消息代理,它实现了 Advanced Message Queuing Protocol (AMQP)...

    spring-amqp-reference-1.6.1.RELEASE

    ### Spring AMQP 1.6.1.RELEASE 知识点详析 #### 一、简介 Spring AMQP 是一个基于 Spring 框架的高级消息队列协议(AMQP)实现,它提供了与多种 AMQP 服务器进行交互的能力。Spring AMQP 的目标是为开发者提供一...

    SpringAMQP资料包

    SpringAMQP

    spring amqp实现异步消息队列的股票系统

    Spring AMQP是一个强大的框架,它将Apache RabbitMQ的消息中间件集成到Spring应用程序中,使得开发者可以轻松地在Java应用中实现异步通信和消息队列的功能。在这个名为"spring-rabbit-stocks"的项目中,我们将深入...

    spring-amqp,spring-retry,spring-rabbit

    标题中的"spring-amqp"、"spring-retry"和"spring-rabbit"是Spring框架的三个关键组件,它们主要用于构建高效、可靠的分布式系统,尤其是在消息传递和错误处理方面。 1. **Spring AMQP**: Spring AMQP是Spring框架...

    spring-amqp 1.5.3源码

    《深入解析Spring AMQP 1.5.3源码》 Spring AMQP是Spring框架的一个扩展,它提供了在Java应用程序中使用Advanced Message Queuing Protocol (AMQP)的全面支持。AMQP是一种开放标准,用于在分布式系统中进行异步消息...

    Spring AMQP 集成完整代码,可运行

    Spring AMQP是Spring框架的一个扩展,它为使用Advanced Message Queuing Protocol(AMQP)提供了一种集成方式。AMQP是一种开放标准,用于在应用程序之间进行异步消息传递,支持多种消息中间件,如RabbitMQ。这个...

    Spring AMQP 工作队列 源码

    Spring AMQP 是一个基于 Apache 2.0 许可证的框架,它为 Spring 应用程序提供了对 Advanced Message Queuing Protocol(AMQP)的全面支持。AMQP 是一种标准的消息中间件协议,用于在分布式系统中高效地传递消息。...

    spring amqp rabbit 标签使用

    在Spring AMQP框架中,RabbitMQ是一种广泛使用的消息中间件,它允许应用程序通过发布和订阅消息来解耦系统组件。本文将详细讲解如何在Spring应用中使用RabbitMQ,并重点探讨`spring-amqp`标签的使用。 首先,我们要...

Global site tag (gtag.js) - Google Analytics