Spring AMQP 2.0.0.M4 发布了,自 M3 以来的更新包括:
- 新的 DirectMessageListnerContainer 现在支持配置在 ack 之间进行消息数量处理
- 现在可以在 @RabbitListener 注释上指定容器并发
Spring AMQP 2.0.0 候选版预计会在6月初发布。
关于 2.0 版本的更新信息, 还可以浏览 2.0.0.M1 、 2.0.0.M2, 以及 2.0.0.M3。
Spring AMQP 是基于 Spring 框架的 AMQP 消息解决方案,提供模板化的发送和接收消息的抽象层,提供基于消息驱动的 POJO。
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(); }
转自 http://www.oschina.net/news/84576/spring-amqp-2-0-0-m-4