【AICon】探索RAG 技术在实际应用中遇到的挑战及应对策略!AICon精华内容已上线73%>>> 了解详情
写点什么

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:433841
用户头像

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

关注

评论

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

坚守在技术无人区,一群无名英雄的低调与浪漫

脑极体

区块链用在房地产交易上 会怎样?

CECBC

模块二作业

hhh

「架构实战营」

模块二作业

莫离

架构实战营 「架构实战营」

01 K8S之容器与容器编排系统

穿过生命散发芬芳

k8s 11月日更

文本序号添加/移除工具

入门小站

工具

宣布Contour v1.13.0!!!

远鹏

golang Kubernetes cncf contour ingress-controller

Serverless 工程实践|自建 Apache OpenWhisk 平台

阿里巴巴云原生

Apache 阿里云 开源 Serverless 云原生

2019-年赚钱最多的-13-个技术岗位,轻松入门flutter

android 程序员 移动开发

16 个好用的 Code Review 工具,绝对干货

android 程序员 移动开发

2017-2020挑选出来最具代表性的(Java,网络相关,2021年字节跳动74道高级程序员面试

android 程序员 移动开发

00后已经进入网易,下一步定位阿里,年轻人这么拼,android开发艺术探索电子

android 程序员 移动开发

2014-2020分享我在Android开发中走的一些弯路,Android开发者必看避坑指南!

android 程序员 移动开发

架构训练营 - 模块2作业

焦龙

架构实战营

18—19年BAT大厂Android高级多套面试专题整理集合(面试资料专题包分享

android 程序员 移动开发

linux之Ansible快速入门

入门小站

Linux

一点思考

williamcai

车联网 网关

区块链技术重构文创产业 首个行业自律公约发布

CECBC

架构实战营 - 模块二 - 微信朋友圈的高性能复杂度分析

dog_brother

架构实战营

01、泛型是什么?,flutterplugin修改

android 程序员 移动开发

2018年Android面试题整理,flutter下拉加载

android 程序员 移动开发

飞桨中国行登陆鹏城 与当地企业共话AI赋能软硬件产品创新

百度大脑

人工智能 百度

极客时间 - 架构实战营 - 模块二作业

秋夫人

架构实战营

飞行汽车能顺利上天吗?

脑极体

连续四年包揽第一!百度AI专利申请量、授权量再度领跑全国

百度大脑

人工智能 百度

2017-2020挑选出来最具代表性的(Java,网络相关(1),面试真题解析

android 程序员 移动开发

OpenVINO+TF2环境搭建

IT蜗壳-Tango

11月日更

模块二作业

忘记喝水的猫

架构训练营

第二模块作业

张靖

#架构实战营

架构班模块二作业

21°Char

事务对系统影响(一)

卢卡多多

事务 11月日更

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