50万奖金+官方证书,深圳国际金融科技大赛正式启动,点击报名 了解详情
写点什么

Spring AMQP 1.0 GA 发布了

  • 2012-02-05
  • 本文字数:1491 字

    阅读完需:约 5 分钟

近日,SpringSource(VMware 下的一个部门)发布 Spring AMQP 1.0 GA(1.0.0.RELEASE)。Spring AMQP 项目将 Spring 核心概念应用到了基于 AMQP 的消息解决方案的开发上,并且提供了 Java 与.NET 两个版本。要想了解 Spring AMQP 与 AMQP,请阅读文章“ Introduction to SpringSource’s Advanced Message Queuing Protocol Support ”。

Spring AMQP 提供了 org.springframework.amqp.core.AmqpTemplate 来发送与接收消息。AMQP 模板实现支持发送与接收 POJOs 而非 javax.jms.Message 实例。他们还提供了一种方式来自定义用于编排对象的 MessageConverter。Spring 与 JMS 用户会发现 JmsTemplate 与新的 AmqpTemplate 之间的相似性。

下面的代码片段介绍了如何联合使用 Spring AMQP 与 RabbitMQ 处理同步消息。 RabbitMQ 是 VMware 的产品,并且是官方 Spring AMQP 示例中所用的默认 AMQP 实现。

复制代码
<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/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<rabbit:connection-factory id="connectionFactory"/>
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"/>
<rabbit:admin connection-factory="connectionFactory"/>
<rabbit:queue name="helloworld.queue"/>
</beans>

上述 Spring 配置 xml 引用了 ConnectionFactory,创建了一个 RabbitTemplate 来访问消息 broker,创建了一个 RabbitAdmin 来管理交换、查询与绑定,最后创建了队列。下面的 Java 代码片段用于发送与接收消息。

复制代码
Producer.java
import org.springframework.amqp.core.AmqpTemplate;
...
AmqpTemplate amqpTemplate = context.getBean(AmqpTemplate.class);
amqpTemplate.convertAndSend("helloworld.queue", "Hello World");
复制代码
Consumer.java
import org.springframework.amqp.core.AmqpTemplate;
...
AmqpTemplate amqpTemplate = context.getBean(AmqpTemplate.class);
System.out.println(amqpTemplate.receiveAndConvert("helloworld.queue"));

要想上手,请下载 Spring AMQP for Java 或是 Spring AMQP for .NET 。Spring AMQP for Java artifacts 也位于 SpringSource Maven 仓库与 Maven Central 中。其依赖是 spring-amqp、spring-core 与 spring-context。如果消息 broker 使用的是 RabbitMQ,那么还要引入 spring-rabbit。你还可以试一下位于 GitHub 上的 Spring AMQP 示例。这些示例都是基于 Maven 的项目,需要用到 RabbitMQ 与 Erlang 。请阅读与示例代码一同发布的 readme.md 文件以了解完整的构建命令。

对于 Cloud Foundry 用户来说,VMware 还发布了RabbitMQ on Cloud Foundry 免费的公开Beta 版。你可以使用AMQP 连接RabbitMQ on Cloud Foundry,通过这些示例可以帮助你快速上手。对于Spring Integration 用户来说,版本2.1 M1 提供了AMQP 支持。

除了VMware 的RabbitMQ 外,其他基于AMQP 面向消息的中间件还有 Apache Qpid Red Hat Enterprise MRG StormMQ (托管)。iMatrix 的 OpenAMQ 已经不再支持了,因此也没有成为一个选择。

要想了解关于 Spring AMQP 的更多信息,请查看 Spring AMQP Reference for Java Spring AMQP Reference for .NET 参考页面。

查看英文原文: Spring AMQP 1.0 GA

2012-02-05 23:434054
用户头像

发布了 88 篇内容, 共 271.9 次阅读, 收获喜欢 9 次。

关注

评论

发布
暂无评论
发现更多内容

网络攻防学习笔记 Day99

穿过生命散发芬芳

态势感知 网络攻防 8月日更

架构实战营-模块4

Cingk

商城异地多活架构

arctec

【架构设计模块四】:设计千万级学生管理系统的考试试卷存储方案

Ryoma

架构师学习心得

ifc177

架构实战营总结

Lane

FastApi-08-路径参数校验

Python研究所

FastApi 8月日更

架构实战营 - 模块 4 - 设计千万级学生管理系统的考试试卷存储方案

雪中亮

架构实战营 #架构实战营

架构实战营-毕业总结

笑春风

高亮架构训练营毕业设计-设计电商秒杀系统

高亮

架构训练营

三个问题,颠覆你的三观

非著名程序员

个人成长 认知提升 个人提升 8月日更

毕业设计:设计电商秒杀系统

Johnny

架构实战营

架构实战营-毕业设计

笑春风

初识宽度优先搜索

泽睿

值值得收藏,揭秘 MySQL 多版本并发控制实现原理

架构精进之路

MySQL MVCC 8月日更

架构实战营 - 模块四

Testcase

架构实战营

毕业设计

青鸟飞鱼

从0开始的TypeScriptの一:启航

空城机

typescript 大前端 8月日更

架构实战营-毕业设计项目

༺NPE༻

架构训练营模块四作业

老实人Honey

架构训练营

业务定制型异地多活架构业务设计

arctec

模块四

Winston

Apache Flink的体系架构(三)

Databri_AI

flink 时间戳

电商秒杀系统设计方案

Lane

二叉树遍历和分治

泽睿

算法 遍历 分治

《项目管理三步法》教你搞定孩子 作业拖延症

Ian哥

读尽天下源码,心中自然无码

程序员阿杜

8月日更

模块四作业

Tina

架构实战营 毕业设计

小遵

学生管理系统的考试试卷存储方案

宁静志远

架构实战营

架构实战营 毕业总结

小遵

Spring AMQP 1.0 GA发布了_Java_Bienvenido David_InfoQ精选文章