amqp activemq_Spring AMQP ActiveMQ教程(第1部分)

amqp activemq

Welcome to Spring AMQP ActiveMQ Tutorial. Earlier we looked into installing Apache ActiveMQ server. Today we will create a spring application to work with ActiveMQ JMS queues.

欢迎使用Spring AMQP ActiveMQ教程。 之前我们研究过安装Apache ActiveMQ服务器。 今天,我们将创建一个Spring应用程序以与ActiveMQ JMS队列一起使用。

Spring AMQP ActiveMQ教程 (Spring AMQP ActiveMQ Tutorial)

The Spring AMQP ActiveMQ Tutorial is divided into following sections.

Spring AMQP ActiveMQ教程分为以下几节。

  • Introduction

    介绍
  • Spring AMQP Tag Libraries

    SpringAMQP标签库
  • Steps to Develop and Test Spring AMQP with ActiveMQ

    使用ActiveMQ开发和测试Spring AMQP的步骤
  • Benefits and Drawbacks of Spring AMQP with ActiveMQ

    带有ActiveMQ的Spring AMQP的优点和缺点
  • Create JMS Queues in ActiveMQ Server

    在ActiveMQ Server中创建JMS队列
  • Create Spring AMQP Configuration for ActiveMQ

    为ActiveMQ创建Spring AMQP配置

介绍 (Introduction)

We have already discussed some “Spring AMQP Basics” Theoretically and “How to install and setup ActiveMQ Server” in my previous posts. Please refer them in the following:

在以前的文章中,我们已经从理论上讨论了一些“ Spring AMQP基础知识”和“如何安装和设置ActiveMQ Server”。 请参考以下内容:

In this post and my next coming post, we are going to develop a Spring AMQP ActiveMQ Messaging application using Queues that is One-to-One Messaging Application. Let us start it now.

在本文和我的下一篇文章中,我们将使用队列(一对一消息传递应用程序)开发Spring AMQP ActiveMQ消息传递应用程序。 让我们现在开始。

Initially I thought of delivering one post for this whole example. However, after preparing whole steps I feel that its too lengthy post. So its divided into two posts. In this post, we are going to discuss some Apache ActiveMQ Basics, then how to configure our application queues then do some Spring Framework AMQP and ActiveMQ API XML Configuration. In my next post, we will develop actual Java programs and test it.

最初,我想为整个示例发表一篇文章。 但是,在准备了所有步骤之后,我觉得它的发布时间太长。 因此将其分为两个职位。 在本文中,我们将讨论一些Apache ActiveMQ基础知识,然后讨论如何配置应用程序队列,然后进行一些Spring Framework AMQP和ActiveMQ API XML配置。 在我的下一篇文章中,我们将开发实际的Java程序并对其进行测试。

Please click here “Spring AMQP ActiveMQ Messaging Example” to access part-2 post.

请单击此处“ Spring AMQP ActiveMQ消息传递示例”以访问第2部分帖子。

SpringAMQP标签库 (Spring AMQP Tag Libraries)

Spring Framework has provided two kinds of AMQP tag library to work with the following AMQP Servers:

Spring框架提供了两种AMQP标签库,可与以下AMQP服务器配合使用:

  • RabbitMQ AMQP Tag Library

    RabbitMQ AMQP标签库
  • Spring RabbitMQ AMQP Tag Library is used to develop Messaging applications for RabbitMQ Server using Spring AMQP API and Spring RabbitMQ API.

    Spring RabbitMQ AMQP标签库用于使用Spring AMQP API和Spring RabbitMQ API为RabbitMQ Server开发消息应用程序。

    Spring RabbitMQ AMQP Tag Library is defined in “spring-rabbit.xsd” file.

    Spring RabbitMQ AMQP标签库在“ spring-rabbit.xsd”文件中定义。

  • ActiveMQ AMQP Tag Library

    ActiveMQ AMQP标签库
  • Spring ActiveMQ AMQP Tag Library is used to develop Messaging applications for Apache ActiveMQ Server using Spring AMQP API and Apache ActiveMQ API.

    Spring ActiveMQ AMQP标记库用于使用Spring AMQP API和Apache ActiveMQ API为Apache ActiveMQ Server开发消息应用程序。

    Spring RabbitMQ AMQP Tag Library is defined in “activemq-core.xsd” file.

    Spring RabbitMQ AMQP标签库在“ activemq-core.xsd”文件中定义。

使用ActiveMQ开发和测试Spring AMQP的步骤 (Steps to Develop and Test Spring AMQP with ActiveMQ)

In this section, I will just list out what are all the steps we need to do to develop and test a Spring AMQP Messaging application with Apache ActiveMQ Server. We will discuss discuss these steps in depth with example in coming sections and coming post.

在本部分中,我将列出我们使用Apache ActiveMQ Server开发和测试Spring AMQP Messaging应用程序所需要做的所有步骤。 我们将在接下来的部分和后续文章中以示例的方式深入讨论这些步骤。

Please follow these steps to develop and test Spring AMQP Messaging application with Apache ActiveMQ Server.

请按照以下步骤使用Apache ActiveMQ Server开发和测试Spring AMQP Messaging应用程序。

  • Install Apache ActiveMQ Server (refer ActiveMQ section)

    安装Apache ActiveMQ Server(请参阅ActiveMQ部分)
  • Create a Mavenized Java project in Eclipse

    在Eclipse中创建Mavenized Java项目
  • Create Spring AMQP Configuration for ActiveMQ

    为ActiveMQ创建Spring AMQP配置
  • Create JMS Queues in ActiveMQ Server

    在ActiveMQ Server中创建JMS队列
  • Develop Spring AMQP Messaging Application With ActiveMQ

    使用ActiveMQ开发Spring AMQP消息传递应用程序
  • Test Spring AMQP Messaging Application With ActiveMQ

    使用ActiveMQ测试Spring AMQP消息传递应用程序

These are the brief steps to develop and test Spring AMQP Messaging application with Apache ActiveMQ Server. If you don’t understand them well, no worries. We will discuss these steps one by one in coming sections.

这些是使用Apache ActiveMQ Server开发和测试Spring AMQP Messaging应用程序的简短步骤。 如果您对它们不太了解,则不必担心。 我们将在接下来的部分中逐一讨论这些步骤。

带有ActiveMQ的Spring AMQP的优点和缺点 (Benefits and Drawbacks of Spring AMQP with ActiveMQ)

In this section, we will discuss: Compare to “Spring AMQP With RabbitMQ Server” combination, what are the benefits and drawbacks of “Spring AMQP With ActiveMQ Server” combination

在本节中,我们将讨论:与“带有RabbitMQ服务器的Spring AMQP”组合相比,“带有ActiveMQ服务器的Spring AMQP”组合的优缺点是什么?

“Spring AMQP With ActiveMQ” combination have the following benefits:

“带有ActiveMQ的Spring AMQP”组合具有以下优点:

  • Apache ActiveMQ Server supports XA Transactions very well.

    Apache ActiveMQ Server非常支持XA Transactions。
  • We can easily embedded Apache ActiveMQ MQ Broker into Java applications.

    我们可以轻松地将Apache ActiveMQ MQ Broker嵌入到Java应用程序中。
  • It is very easy to integrate “Spring AMQP With ActiveMQ Application” with Apache Camel.

    将“带有ActiveMQ应用程序的Spring AMQP”与Apache Camel集成非常容易。

Even though “Spring AMQP With ActiveMQ” combination have many benefits, it has one major drawback:

即使“带有ActiveMQ的Spring AMQP”组合有很多好处,它也有一个主要缺点:

  • ActiveMQ needs more memory to maintain the application.

    ActiveMQ需要更多内存来维护应用程序。

在ActiveMQ Server中创建JMS队列 (Create JMS Queues in ActiveMQ Server)

  • Create JMS Queue by using new ActiveMQ Admin console

    使用新的ActiveMQ管理控制台创建JMS队列
  • Click on “+Create” button, provide details and click on “Create Queue” button

    单击“ +创建”按钮,提供详细信息,然后单击“创建队列”按钮
  • Click on “Browse” button to view messages

    单击“浏览”按钮以查看消息

为ActiveMQ创建Spring AMQP配置 (Create Spring AMQP Configuration for ActiveMQ)

  • Configure Spring AMQP XML Configuration for ActiveMQ Server

    为ActiveMQ服务器配置Spring AMQP XML配置
  • Configure JMS Connection Factory by providing ActiveMQ Provider URL

    通过提供ActiveMQ提供程序URL配置JMS连接工厂

<amq:connectionFactory id="jmsFactory" brokerURL="tcp://localhost:61616" />

Here URL contains protocol, host name and port number.By default, this application needs tcp protocol. Host name is localhost. We are using default port number 61616.

URL中包含协议,主机名和端口号。默认情况下,此应用需要tcp协议。 主机名是localhost。 我们正在使用默认端口号61616。

  • Configure destination (Here we are using queue)

    配置目标(此处使用队列)
  • <amq:queue id="destination" physicalName="jms/TPActiveMQQueue" />
  • Declare Producer Connection Factory by using Spring JMS API’s SingleConnectionFactory

    通过使用Spring JMS API的SingleConnectionFactory声明Producer连接工厂
  • <bean id="jmsProducerConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
    	<property name="targetConnectionFactory" ref="jmsFactory" />
    </bean>
  • Declare Consumer Connection Factory by using Spring JMS API’s SingleConnectionFactory

    使用Spring JMS API的SingleConnectionFactory声明使用者连接工厂
  • <bean id="jmsConsumerConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
    	<property name="targetConnectionFactory" ref="jmsFactory" />
    </bean>

    NOTE:-
    Both Producer and Consumer should refer to the previously created JMS Factory object as shown in the above Spring AMQP XML Configuration.

    注意:-
    生产者和使用者都应引用先前创建的JMS Factory对象,如上面的Spring AMQP XML配置所示。

  • Configure Spring JmsTemplate for JMS Producer to send messages to Destination

    为JMS Producer配置Spring JmsTemplate以将消息发送到Destination
  • <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    	<property name="connectionFactory" ref="producerJmsConnectionFactory" />
    	<property name="defaultDestination" ref="destination" />
    </bean>
  • Configure JMS Listener to consume messages

    配置JMS侦听器以使用消息
  • <jms:listener-container container-type="default" connection-factory="consumerJmsConnectionFactory" acknowledge="auto">
    <jms:listener destination="jms/TPActiveMQQueue" ref="activeMQMessageListener" />
    </jms:listener-container>
  • Complete Spring Configuration file:

    完整的Spring配置文件:
  • <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="https://www.springframework.org/schema/beans"
           xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="https://www.springframework.org/schema/context"
           xmlns:jms="https://www.springframework.org/schema/jms"
           xmlns:amq="https://activemq.apache.org/schema/core"
           xsi:schemaLocation="https://www.springframework.org/schema/beans 
           https://www.springframework.org/schema/beans/spring-beans.xsd
           https://www.springframework.org/schema/context 
           https://www.springframework.org/schema/context/spring-context.xsd
           https://www.springframework.org/schema/jms 
           https://www.springframework.org/schema/jms/spring-jms.xsd
           https://activemq.apache.org/schema/core 
           https://activemq.apache.org/schema/core/activemq-core.xsd">
    
    <context:component-scan base-package="com.tp.jms.activemq" />
    <amq:connectionFactory id="jmsFactory" brokerURL="tcp://localhost:61616" />
    <amq:queue id="destination" physicalName="jms/TPActiveMQQueue" />
    
    <bean id="producerJmsConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
    	<property name="targetConnectionFactory" ref="jmsFactory" />
    </bean>
    
    <bean id="consumerJmsConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
    	<property name="targetConnectionFactory" ref="jmsFactory" />
    </bean>
    
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    	<property name="connectionFactory" ref="producerJmsConnectionFactory" />
    	<property name="defaultDestination" ref="destination" />
    </bean>
    
    <jms:listener-container container-type="default" connection-factory="consumerJmsConnectionFactory" acknowledge="auto">
    <jms:listener destination="jms/TPActiveMQQueue" ref="activeMQMessageListener" />
    </jms:listener-container>
    
    <bean id="counter" class="java.util.concurrent.atomic.AtomicInteger"/>
    </beans>

    That’s it all about Spring XML Configuration to develop a Spring AMQP ActiveMQ Messaging Example. Please head over to Spring ActiveMQ Example for the second part of this tutorial.

    这就是关于Spring XML Configuration开发Spring AMQP ActiveMQ Messaging Example的全部内容。 请转到本教程第二部分的Spring ActiveMQ示例

    翻译自: https://www.journaldev.com/12697/spring-amqp-activemq-tutorial

    amqp activemq

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值