项目地址
http://spring.io/projects

提供了对AMOP的支持
提供了RabbitMQ的实现
http://spring.io/projects/spring-amqp

配置文件

第一步,定义连接工厂
第二步,定义模板,可以指定交换机或队列
第三步,定义队列、交换机、以及完成队列和交换机的绑定
第四步,定义监听
第五步,定义管理,用于管理队列、交换机等

Durable
表示对持久化的配置
True,表示持久化
False,表示非持久化

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rabbit="http://www.springframework.org/schema/rabbit"xsi:schemaLocation="http://www.springframework.org/schema/rabbithttp://www.springframework.org/schema/rabbit/spring-rabbit-1.4.xsdhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsd"><!-- 定义RabbitMQ的连接工厂 --><rabbit:connection-factory id="connectionFactory"host="127.0.0.1" port="5672" username="taotao" password="taotao"virtual-host="/taotao" /><!-- 定义Rabbit模板,指定连接工厂以及定义exchange --><rabbit:template id="amqpTemplate" connection-factory="connectionFactory"exchange="fanoutExchange" /><!-- <rabbit:template id="amqpTemplate" connection-factory="connectionFactory" exchange="fanoutExchange" routing-key="foo.bar" /> --><!-- MQ的管理,包括队列、交换器等 --><rabbit:admin connection-factory="connectionFactory" /><!-- 定义队列,自动声明 --><rabbit:queue name="myQueue" auto-declare="true" /><!-- 定义交换器,自动声明 --><rabbit:fanout-exchange name="fanoutExchange"auto-declare="true" durable="true"><rabbit:bindings><rabbit:binding queue="myQueue" /></rabbit:bindings></rabbit:fanout-exchange><!-- <rabbit:topic-exchange name="myExchange"> <rabbit:bindings> <rabbit:binding queue="myQueue" pattern="foo.*" /> </rabbit:bindings> </rabbit:topic-exchange> --><!-- 队列监听 --><rabbit:listener-container
        connection-factory="connectionFactory"><rabbit:listener ref="foo" method="listen"queue-names="myQueue" /></rabbit:listener-container><bean id="foo" class="cn.itcast.rabbitmq.spring.Foo" /></beans>

生产者

package cn.itcast.rabbitmq.spring;import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class SpringMain {public static void main(final String... args) throws Exception {AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:spring/rabbitmq-context.xml");//RabbitMQ模板RabbitTemplate template = ctx.getBean(RabbitTemplate.class);//发送消息template.convertAndSend("Hello, world!");Thread.sleep(1000);// 休眠1秒ctx.destroy(); //容器销毁}
}

消费者

package cn.itcast.rabbitmq.spring;/*** 消费者* @author zhijun**/
public class Foo {//具体执行业务的方法public void listen(String foo) {System.out.println("消费者: " + foo);}
}

运行

Spring RabbitMQ使用相关推荐

  1. rabbitmq配置文件字段spring.rabbitmq.publisher-confirms过时

    spring.rabbitmq.publisher-confirms过时解决 在properties文件中确认消息报红 因为源码中过时配置级别设置了Error 新版本jar包配置换了就可以了 spri ...

  2. Spring RabbitMQ教程

    Spring RabbitMQ教程  Spring RabbitMQ是基于Spring AMQP协议实现的消息代理. 目录[ 隐藏 ] 1 Spring RabbitMQ 1.1 Spring AMQ ...

  3. RabitMQ系列之 Spring RabbitMQ流量削锋实现案例之抢红包

    一.案例说明:电商的秒杀和抢购,对我们来说,都不是一个陌生的东西.然而,从技术的角度来说,这对于Web系统是一个巨大的考验,我们都知道,秒杀类,抢购类应用都有一个共同点,即瞬时请求巨大.本文中用一个多 ...

  4. spring.rabbitmq.template.mandatory 和spring.rabbitmq.publisher-returns

    在SpringBoot的RabbitMQ配置中,有如下一项: spring.rabbitmq.template.mandatory = true 官方注释: Enable mandatory mess ...

  5. Failed to bind properties under ‘spring.rabbitmq.publisher-confirm-type‘ to org.springfram

    翻译:无法将"spring.rabbitmq.publisher确认类型"下的属性绑定到org.springframework.amqp.rabbit.connection.Cac ...

  6. Spring rabbitmq消息机制--手动确认

    首先我们在Spring.xml中配置相关的消费者 在配置的时候可以指定是手动确认还是自动的确认,比如: <!-- 定义消息监听队列 --><rabbit:queue id=" ...

  7. Spring - RabbitMQ循环依赖问题解决

    代码整合 actuator 后,启动报错,出现rabbitMQ循环依赖的问题 异常信息: *************************** APPLICATION FAILED TO START ...

  8. RabbitMQ使用及与spring boot整合

    1.MQ 消息队列(Message Queue,简称MQ)--应用程序和应用程序之间的通信方法 应用:不同进程Process/线程Thread之间通信 比较流行的中间件: ActiveMQ Rabbi ...

  9. Spring Cloud(十一)高可用的分布式配置中心 Spring Cloud Bus 消息总线集成(RabbitMQ)

    上一篇文章,留了一个悬念,Config Client 实现配置的实时更新,我们可以使用 /refresh 接口触发,如果所有客户端的配置的更改,都需要手动触发客户端 /refresh ,当服务越来越多 ...

最新文章

  1. ajax就收data的参数
  2. php中extends是什么意思,在php中extends与implements的区别
  3. 团队作业8——测试与发布(Beta阶段)
  4. [Java基础]Date类基础
  5. git是一种分布式代码管理工具,git通过树的形式记录文件的更改历史,比如: base'--base--A--A' ^ | --- B--B' 小米工程师常常需要寻找两个分支最近的分割点,即b...
  6. VB 和Flex交互总结
  7. 《AngularJS高级程序设计》学习笔记
  8. ASP.NET Core 基础教程总结 - ASP.NET Core 基础教程 - 简单教程,简单编程
  9. 怎样快速熟悉公司产品
  10. Memory Limit Exceeded
  11. 电脑只能上QQ不能开网页
  12. 第二十九章 狼心狗肺
  13. python怎么念1001python怎么念-python 星号的使用
  14. VMware错误:无法更新运行时文件夹共享状态:在客户机操作系统内装载共享文件夹文件系统时出错
  15. centos 磁盘重新分区操作实践
  16. Python-爬虫请求~requsts~get
  17. thinkphp创建临时表
  18. python开源oa系统_最全总结 | 聊聊 Python 办公自动化之 Word(下)
  19. 模块电路选型(6)----存储模块
  20. 曙光g20服务器芯片组驱动,曙光i620-g20阵列卡驱动

热门文章

  1. Loudrunner常用函数
  2. 黑马程序员--学习while、do-while、for循环、try-catch的用法
  3. stm32f103c8t6芯片IAP升级填坑记
  4. JavaScript定时器原理及高级使用
  5. 强化学习(五)—— AlphaGo与Alpha Zero
  6. Attention的本质:从Encoder-Decoder(Seq2Seq)理解
  7. C++ Primer 5th笔记(chap 17 标准库特殊设施)指定浮点数记数法
  8. 区块链BaaS云服务(39)时戳信息Bystack“架构“
  9. 深入解析 Kubebuilder:让编写 CRD 变得更简单
  10. ++i 和 i++ 效率分析(C++)