Before going to through this post, please read my previous post at “JMS API 1.1 Producer and Consumer” to understand some baby steps to develop JMS 1.1 Producer and Consumer programs.

在阅读这篇文章之前,请阅读我以前在“ JMS API 1.1 Producer和Consumer”上的文章,以了解开发JMS 1.1 Producer和Consumer程序的一些基本步骤。

In this post, we are going to develop a Simple JMS 1.1 Producer and Consumer Example With Eclipse IDE and Embedded JBoss HornetQ Server.

在本文中,我们将使用Eclipse IDE和嵌入式JBoss HornetQ Server开发一个简单的JMS 1.1生产者和使用者示例。

发表简短目录 (Post Brief TOC)

  • Introduction
    介绍
  • Steps to Develop a JMS V.1.1 Example
    开发JMS V.1.1示例的步骤
  • Final Project Structure
    最终项目结构
  • Execute and Observe the Output
    执行并观察输出

介绍 (Introduction)

As a Novice Developer to JMS API, it is bit tough to understand about JMS Servers, ConnectionFactory Creation, Queue Creation, Topic Creation etc. We will discuss these concepts in detail in coming posts. First of all, we should understand how to write a simple JMS Producer and Consumer programs without much effort.

作为JMS API的新手开发人员,很难理解JMS服务器,ConnectionFactory创建,队列创建,主题创建等。我们将在以后的文章中详细讨论这些概念。 首先,我们应该了解如何轻松编写简单的JMS Producer和Consumer程序。

To develop this example, we are going to use Eclipse IDE, JMS 1.1 API, Maven and JBoss Embedded HornetQ JMS Server. It is very easy to configure ConnectionFactory, Queue, Topic etc. with this embedded server. We just need to configure some XML files.

为了开发该示例,我们将使用Eclipse IDE,JMS 1.1 API,Maven和JBoss Embedded HornetQ JMS Server。 使用此嵌入式服务器配置ConnectionFactory,Queue,Topic等非常容易。 我们只需要配置一些XML文件。

To use Embedded JMS Server, we don’t need to download and install any software. We just need to configure some Jars in our Maven Project. Let’s start developing application now.

要使用Embedded JMS Server,我们不需要下载和安装任何软件。 我们只需要在我们的Maven项目中配置一些Jars。 现在开始开发应用程序。

开发JMS V.1.1示例的步骤: (Steps to Develop a JMS V.1.1 Example:)

  • Create a Mavenized Java project in Eclipse IDE
    在Eclipse IDE中创建Mavenized Java项目
  • Project Name: EmbeddedJMS1.1Example

    项目名称: EmbeddedJMS1.1Example

  • Use the following pom.xml file.
    使用以下pom.xml文件。
<project xmlns="https://maven.apache.org/POM/4.0.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.journaldev.jms</groupId><artifactId>EmbeddedJMS1.1Example</artifactId><version>1.0.0</version><dependencies><dependency><groupId>org.hornetq</groupId><artifactId>hornetq-core</artifactId><version>2.3.0.BETA1</version></dependency>    <dependency><groupId>org.hornetq</groupId><artifactId>hornetq-jms-client</artifactId><version>2.3.0.BETA1</version></dependency>   <dependency><groupId>org.hornetq</groupId><artifactId>hornetq-jms-server</artifactId><version>2.3.0.BETA1</version></dependency>     <dependency><groupId>javax.jms</groupId><artifactId>javax.jms-api</artifactId><version>1.1</version></dependency>   </dependencies>
</project>

NOTE:-This pom.xml contains 3 dependencies

注意:-此pom.xml包含3个依赖项

  1. hornetq-core-x.x.jar:- It contains to provide base API for both JMS server and client programs.
    hornetq-core-xxjar:它包含为JMS服务器和客户端程序提供基本API。
  2. hornetq-jms-server-x.x.jar:- It contains API to provide Embedded JBoss HornetQ Server.
    hornetq-jms-server-xxjar:-包含用于提供嵌入式JBoss HornetQ服务器的API。
  3. hornetq-core-x.x.jar:- It contains JMS API implementation for JMS Session,Queue,Topic etc.
    hornetq-core-xxjar:-包含用于JMS会话,队列,主题等的JMS API实现。
  • Configure one user in “hornetq-users.xml”t o run this program.
    在“ hornetq-users.xml”中配置一个用户以运行该程序。
  • hornetq-users.xml

    hornetq-users.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration xmlns="urn:hornetq"
    xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:hornetq /schema/hornetq-users.xsd"><defaultuser name="jduser" password="jduser"><role name="jduser"/></defaultuser>
    </configuration>

    Here we have defined one user “jduser” to use them in HornetQ Configuration XML file to configure Security.

    在这里,我们定义了一个用户“ jduser”以在HornetQ Configuration XML文件中使用它们来配置安全性。

  • Configure in-memory server configuration “hornetq-configuration.xml” to run this program. It is used to configure In-Memory JMS Server.
    配置内存服务器配置“ hornetq-configuration.xml”以运行该程序。 它用于配置内存JMS服务器。
  • hornetq-configuration.xml

    hornetq-configuration.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration xmlns="urn:hornetq" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd"><persistence-enabled>false</persistence-enabled><connectors><connector name="in-vm"><factory-class>org.hornetq.core.remoting.impl.invm.InVMConnectorFactory</factory-class></connector></connectors><acceptors><acceptor name="in-vm"><factory-class>org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory</factory-class></acceptor></acceptors><security-settings><security-setting match="#"><permission type="consume" roles="jduser"/><permission type="send" roles="jduser"/></security-setting></security-settings></config

    Here We have configured JBoss HornetQ In-Memory Server and Security details.

    在这里,我们已经配置了JBoss HornetQ内存服务器和安全性详细信息。

  • Configure in-memory server ConnectionFactory and Queue “hornetq-jms.xml” to run this program. It is used to configure JMS Settings.
    配置内存服务器ConnectionFactory和队列“ hornetq-jms.xml”以运行该程序。 它用于配置JMS设置。
  • hornetq-jms.xml

    hornetq-jms.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration xmlns="urn:hornetq"
    xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd"><connection-factory name="JDConnectionFactory"><connectors><connector-ref connector-name="in-vm"/></connectors><entries><entry name="JDConnectionFactory"/></entries></connection-factory><queue name="JDQueue"><entry name="/queue/JDQueue"/></queue>
    </configuration>

    Here we have configured ConnectionFactory with “JDConnectionFactory” name and Queue destination with “/queue/JDQueue” JNDI name. We have linked these two things to previous configured JBoss HornetQ In-Memory Server.

    在这里,我们为ConnectionFactory配置了“ JDConnectionFactory”名称,并为队列目标配置了“ / queue / JDQueue” JNDI名称。 我们已经将这两件事链接到先前配置的JBoss HornetQ内存服务器。

  • Create a Simple Java class “EmbeddedHornetQJMSExample” and copy below sample code.
    创建一个简单的Java类“ EmbeddedHornetQJMSExample”,然后复制以下示例代码。
  • package com.jd.embedded.jms.hornetq;import javax.jms.*;
    import org.hornetq.jms.server.embedded.EmbeddedJMS;public class EmbeddedHornetQJMSExample
    {public static void main(final String[] args){try{// This EmbeddedJMS class acts as a JMSServer for example: JBoss HornetQ ServerEmbeddedJMS jmsServer = new EmbeddedJMS();jmsServer.start();System.out.println("JD: Embedded JMS Server started.");ConnectionFactory connectionFactory = (ConnectionFactory)jmsServer.lookup("JDConnectionFactory");Queue queue = (Queue)jmsServer.lookup("/queue/JDQueue");Connection connection = null;try{connection = connectionFactory.createConnection();Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);//1. Producer Code StartMessageProducer producer = session.createProducer(queue);TextMessage message = session.createTextMessage("Hello, I'm from JournalDev(JD).");System.out.println("Sending message: " + message.getText());producer.send(message);//2. Consumer Code StartMessageConsumer messageConsumer = session.createConsumer(queue);connection.start();TextMessage messageReceived = (TextMessage)messageConsumer.receive(1000);System.out.println("Received message: " + messageReceived.getText());}finally{if (connection != null){connection.close();}jmsServer.stop();System.out.println("JD: Embedded JMS Server stopped.");}}catch (Exception e){e.printStackTrace();}}
    }

    Just for simplicity, I’ve created both Message Producer and Consumer in a single Java file. Please go through those two sub-sections(separated by comments) for understanding purpose.

    为了简单起见,我在单个Java文件中创建了消息生产者和使用者。 请仔细阅读这两个小节(以注释分隔)以了解目的。

    最终项目结构:- (Final Project Structure:-)

    If we observe the project in Eclipse IDE, it’s final structure looks like as below:

    如果我们在Eclipse IDE中观察该项目,则其最终结构如下所示:

    执行并观察输出: (Execute and Observe the Output:-)

    In this section, we will run our JMS Program and observe the results in Eclipse IDE Console.

    在本节中,我们将运行JMS程序并在Eclipse IDE控制台中观察结果。

    • Right click on “EmbeddedHornetQJMSExample.java” Program
      右键单击“ EmbeddedHornetQJMSExample.java”程序
    • Run it as “Java Application”
      作为“ Java应用程序”运行
    • Observe the output in Eclipse IDE Console
      在Eclipse IDE控制台中观察输出
    • Here we can see both Producer Sent message and Consumer Received message.

      在这里,我们可以看到生产者已发送消息和消费者已接收消息。

    That’s it all about developing Simple JMS API 1.1 Producer and Consumer application with Embedded JBoss HornetQ Server. We will discuss JMS API 2.0 Producer and Consumer Example in my coming posts.

    这就是使用嵌入式JBoss HornetQ Server开发Simple JMS API 1.1 Producer和Consumer应用程序的全部内容。 我们将在我的后续文章中讨论JMS API 2.0生产者和使用者示例。

    Please drop me a comment if you like my post or have any issues/suggestions.

    如果您喜欢我的帖子或有任何问题/建议,请给我评论。

    翻译自: https://www.journaldev.com/9858/jms1-1-producer-consumer-embedded-jboss-hornetq-example

具有Eclipse和嵌入式JBoss HornetQ Server的简单JMS 1.1生产者和使用者示例相关推荐

  1. ejb 2.1 jboss_带有Eclipse IDE,EJB Project和JBoss 6.0 AS的JMS 1.1生产者和使用者示例

    ejb 2.1 jboss Please go through my previous posts to understand some JMS Concepts and JMS 1.1 API Ba ...

  2. jboss hornetq jms 用户文档

    HornetQ 2.1用户手册 Putting the buzz in messaging Table of Contents 1. 法律声明 2. 前言 3. 项目信息 3.1. 软件下载 3.2. ...

  3. 包含Tomcat 9的JBoss Web Server 5已发布

    Red Hat JBoss Web Server(JWS)将Apache服务器与Tomcat相结合,用于构建.部署和维护Web应用程序和大型网站.JBoss Web Server 5最近发布,支持To ...

  4. 适用于孩子,父母和祖父母的JBoss HornetQ –第1章

    现在与HornetQ合作已经快4年了,我认为是时候分享我到目前为止所学知识的一部分了. 这篇文章的主要目的不是重写官方文档 ,而是以简单的方式阐明我们在PaddyPower中最常用的概念. 什么是Ho ...

  5. eclipse 配置java路径_Java修改eclipse中web项目的server部署路径问题

    和MyEclipse不一样,在Eclipse中做的Web项目默认是不支持将项目发布到Web服务器上的,会发布到工作空间的某个目录,因此无法在外部启动Tomcat来运行Web项目,只有打开Eclipse ...

  6. 多数据源使用spring-data-jpa无法部署到JBoss As Server

    2019独角兽企业重金招聘Python工程师标准>>> 1.异常信息 Caused by: java.lang.IllegalArgumentException: JBAS01147 ...

  7. 如何使用eclipse进行嵌入式Linux的开发

    作者:曾宏安,华清远见嵌入式学院高级讲师. 如何使用eclipse进行嵌入式Linux的开发 习惯了在windows环境下开发的程序员在转到Linux平台时经常会抱怨没有一个好用的集成开发环境.和wi ...

  8. jboss 不适用内置日志_适用于孩子,父母和祖父母的JBoss HornetQ –第1章

    jboss 不适用内置日志 现在与HornetQ合作已经快4年了,我认为现在该分享我到目前为止所学的部分知识了. 这篇文章的主要目的不是重写官方文档 ,而是以简单的方式阐明我们在PaddyPower中 ...

  9. java项目如何更改路径_Java修改eclipse中web项目的server部署路径问题

    和MyEclipse不一样,在Eclipse中做的Web项目默认是不支持将项目发布到Web服务器上的,会发布到工作空间的某个目录,因此无法在外部启动Tomcat来运行Web项目,只有打开Eclipse ...

最新文章

  1. PHP创建日志记录(已封装)
  2. JavaEE框架整合之基于注解的SSH整合
  3. 密码学基础知识(三)古典密码
  4. CCF OJ 1113-括号匹配[栈]
  5. 【推荐系统】协同过滤 零基础到入门
  6. 安卓入门系列-01开发工具Android Studio的安装
  7. 未声明spire。它可能因保护级别而不可访问_信息系统安全:访问控制技术概述...
  8. 【Python】如何判断一个字符串为空
  9. SAP 学习笔记 --- 04-26 02.Material Master
  10. java:Eclipse插件springsource-tool-suite的下载和安装
  11. word 的脚注横线和文字怎么调整为左对齐?
  12. Cannot resolve MVC View
  13. cloudstack vpc network egress-ingress rules
  14. Mysql中时间格式转换
  15. 向大家隆重介绍Impel计划
  16. ScanNet: Richly-annotated 3D Reconstructions of Indoor Scenes
  17. Xcode info.plist各种key
  18. ubuntu/linux命令记录 长期更新
  19. maya腿的蒙皮旋转枢轴_MAYA更改、移动枢轴点
  20. Android:This usually happens when two views of different type have the same id in the same hierarchy

热门文章

  1. 朋友,决定了就去做.
  2. [转载] Python 内置函数 dir()
  3. [转载] python字符串处理函数汇总
  4. FPGA中数的表示方法
  5. hdu1113 Word Amalgamation(详解--map和string的运用)
  6. .Net与 WebAssembly 随笔
  7. Centos7——NFS(Network File System)服务
  8. spark streaming限制吞吐
  9. 关于 java jdk 环境变量的配置
  10. Android编译过程详解(三)