當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring RabbitMQ使用
生活随笔
收集整理的這篇文章主要介紹了
Spring RabbitMQ使用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
項目地址
http://spring.io/projects
提供了對AMOP的支持
提供了RabbitMQ的實(shí)現(xiàn)
http://spring.io/projects/spring-amqp
配置文件
第一步,定義連接工廠
第二步,定義模板,可以指定交換機(jī)或隊列
第三步,定義隊列、交換機(jī)、以及完成隊列和交換機(jī)的綁定
第四步,定義監(jiān)聽
第五步,定義管理,用于管理隊列、交換機(jī)等
Durable
表示對持久化的配置
True,表示持久化
False,表示非持久化
生產(chǎn)者
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);//發(fā)送消息template.convertAndSend("Hello, world!");Thread.sleep(1000);// 休眠1秒ctx.destroy(); //容器銷毀} }消費(fèi)者
package cn.itcast.rabbitmq.spring;/*** 消費(fèi)者* @author zhijun**/ public class Foo {//具體執(zhí)行業(yè)務(wù)的方法public void listen(String foo) {System.out.println("消費(fèi)者: " + foo);} }運(yùn)行
總結(jié)
以上是生活随笔為你收集整理的Spring RabbitMQ使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RabbitMQ消息的确认模式
- 下一篇: Freemarker整合Spring