AMQP消息解决方案SpringAMQP.zip

时间:2022-08-06 14:31:46
【文件属性】:

文件名称:AMQP消息解决方案SpringAMQP.zip

文件大小:1.25MB

文件格式:ZIP

更新时间:2022-08-06 14:31:46

开源项目

Spring AMQP 是基于 Spring 框架的 AMQP 消息解决方案,提供模板化的发送和接收消息的抽象层,提供基于消息驱动的 POJO。同时有 Java 和 .NET 的版本。示例代码: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(); } 标签:Spring


网友评论