博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring-Rabbit官方示例
阅读量:7053 次
发布时间:2019-06-28

本文共 1974 字,大约阅读时间需要 6 分钟。

hot3.png

http://projects.spring.io/spring-amqp/

    
        
org.springframework.amqp
        
spring-rabbit
        
1.4.4.RELEASE
    

just Java...

public static void main(final String... args) throws Exception {     ConnectionFactory cf = new CachingConnectionFactory();     // set up the queue, exchange, binding on the broker     RabbitAdmin admin = new RabbitAdmin(cf);     Queue queue = new Queue("myQueue");     admin.declareQueue(queue);     TopicExchange exchange = new TopicExchange("myExchange");    admin.declareExchange(exchange);     admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("foo.*"));     // set up the listener and container     SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf);     Object listener = new Object() {             public void handleMessage(String foo) {             System.out.println(foo);         }      };     MessageListenerAdapter adapter = new MessageListenerAdapter(listener);     container.setMessageListener(adapter);     container.setQueueNames("myQueue");     container.start();     // send something     RabbitTemplate template = new RabbitTemplate(cf);     template.convertAndSend("myExchange", "foo.bar", "Hello, world!");     Thread.sleep(1000);     container.stop(); }

Or, the Spring way...

public static void main(final String... args) throws Exception {     AbstractApplicationContext ctx =         new ClassPathXmlApplicationContext("context.xml");     RabbitTemplate template = ctx.getBean(RabbitTemplate.class);     template.convertAndSend("Hello, world!");     Thread.sleep(1000);     ctx.destroy(); }
public class Foo {     public void listen(String foo) {         System.out.println(foo);     }  }
 
 
 
 
         
                 
         
  
     
  

转载于:https://my.oschina.net/u/1045177/blog/408366

你可能感兴趣的文章
QT编写TCP的问题
查看>>
poj1456 结构体排序+贪心
查看>>
第26天:js-$id函数、焦点事件
查看>>
iOS开发-Alpha,Hidden与Opaque区别
查看>>
CSS中nth-child和nth-of-type的简单使用
查看>>
javascript 乘法口诀表
查看>>
views 视图函数
查看>>
MySql详解(一)
查看>>
解题思路:蓄水池问题
查看>>
android 实时显示系统时间
查看>>
fatal error: asm/system.h: No such file or directory
查看>>
为什么要设计
查看>>
SerializableObj
查看>>
2018年5月31日笔记
查看>>
(转)CentOs上配置samba服务
查看>>
Photoshop给草坪上的人物加上唯美的紫色霞光
查看>>
移动平台对 META 标签的定义
查看>>
curl 命令详解
查看>>
启动改为本地Ip
查看>>
云服务器CentOS7.5安装MySQL5.7
查看>>