最近项目中需要集成消息中间件来处理消息,选择了ActiveMQ这款中间件的开源产品。由于项目用的应用服务器为JBOSS,所以自然就想到如何把两者结合使用。

在ActiveMQ官方网站中给出了答案,网站中用到的是

ActiveMQ4.0.1+JBOSS4.0.4+JDK1.5+ANT1.6.2,我们项目中用的是

jboss-5.1.0.GA+JDK1.7+ActiveMQ5.7.0另外用ANT1.8.4做的集成测试。

ActiveMQ和JBOSS集成地址:http://activemq.apache.org/integrating-apache-activemq-with-jboss.html

具体做法:

1.        安装JDK(不说了,too easy)

2.        安装JBOSS(解压就好)

3.        下载ActiveMQ的rar资源组件包【老版本的ActiveMQ在ActiveMQ压缩包中就有,新版本的压缩包中没有需要单独下载】(如何对J2EE的容器组件开发模型了解的都清楚,j2ee中有五个组件,其中有一个就是资源组件,我们要下载的ActiveMQ的rar文件就是一个资源组件):

https://repository.cloudera.com/content/groups/cdh-build/org/apache/activemq/activemq-rar/5.7.0/

4.        解压RAR拷贝到JBOSS的default/deploy中

5.        配置 activemq(1):修改 META-INF/ra.xml

[html] view plaincopy

print?

  1. <?xmlversionxmlversion="1.0"encoding="UTF-8"?>
  2. <!--
  3. Licensed to the Apache Software Foundation(ASF) under one or more
  4. contributor license agreements.  See the NOTICE file distributed with
  5. this work for additional informationregarding copyright ownership.
  6. The ASF licenses this file to You under theApache License, Version 2.0
  7. (the "License"); you may not usethis file except in compliance with
  8. the License.  You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreedto in writing, software
  11. distributed under the License isdistributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.
  13. See the License for the specific languagegoverning permissions and
  14. limitations under the License.
  15. -->
  16. <connectorxmlnsconnectorxmlns="http://java.sun.com/xml/ns/j2ee"
  17. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  18. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  19. http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
  20. version="1.5">
  21. <description>ActiveMQ  inbound and outbound JMSResourceAdapter</description>
  22. <display-name>ActiveMQ JMS ResourceAdapter</display-name>
  23. <vendor-name>activemq.org</vendor-name>
  24. <eis-type>JMS 1.1</eis-type>
  25. <resourceadapter-version>1.0</resourceadapter-version>
  26. <license>
  27. <description>
  28. Licensed to the Apache Software Foundation(ASF) under one or more
  29. contributor license agreements.  See the NOTICE file distributed with
  30. this work for additional informationregarding copyright ownership.
  31. The ASF licenses this file to You under theApache License, Version 2.0
  32. (the "License"); you may not usethis file except in compliance with
  33. the License.  You may obtain a copy of the License at
  34. http://www.apache.org/licenses/LICENSE-2.0
  35. Unless required by applicable law or agreedto in writing, software
  36. distributed under the License isdistributed on an "AS IS" BASIS,
  37. WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.
  38. See the License for the specific languagegoverning permissions and
  39. limitations under the License.
  40. </description>
  41. <license-required>true</license-required>
  42. </license>
  43. <resourceadapter>
  44. <resourceadapter-class>org.apache.activemq.ra.ActiveMQResourceAdapter</resourceadapter-class>
  45. <config-property>
  46. <description>
  47. The URL to the ActiveMQ serverthat you want this connection to connect to. If using
  48. an embedded broker, this valueshould be 'vm://localhost'.
  49. </description>
  50. <config-property-name>ServerUrl</config-property-name>
  51. <config-property-type>java.lang.String</config-property-type>
  52. <!--<config-property-value>tcp://localhost:61616</config-property-value>-->
  53. <config-property-value>vm://localhost</config-property-value>
  54. </config-property>
  55. <config-property>
  56. <description>The default username that will be used to establish connections to the ActiveMQserver.</description>
  57. <config-property-name>UserName</config-property-name>
  58. <config-property-type>java.lang.String</config-property-type>
  59. <config-property-value>defaultUser</config-property-value>
  60. </config-property>
  61. <config-property>
  62. <description>The defaultpassword that will be used to log the default user into the ActiveMQserver.</description>
  63. <config-property-name>Password</config-property-name>
  64. <config-property-type>java.lang.String</config-property-type>
  65. <config-property-value>defaultPassword</config-property-value>
  66. </config-property>
  67. <config-property>
  68. <description>The client idthat will be set on the connection that is established to the ActiveMQserver.</description>
  69. <config-property-name>Clientid</config-property-name>
  70. <config-property-type>java.lang.String</config-property-type>
  71. </config-property>
  72. <config-property>
  73. <description>Boolean to configureif outbound connections should reuse the inbound connection's session forsending messages.</description>
  74. <config-property-name>UseInboundSession</config-property-name>
  75. <config-property-type>java.lang.Boolean</config-property-type>
  76. <config-property-value>false</config-property-value>
  77. </config-property>
  78. <!-- NOTE disable the following propertyif you do not wish to deploy an embedded broker -->
  79. <config-property>
  80. <description>
  81. Sets the XML configuration file used toconfigure the embedded ActiveMQ broker via
  82. Spring if using embedded mode.
  83. BrokerXmlConfig is the filenamewhich is assumed to be on the classpath unless
  84. a URL is specified. So a value offoo/bar.xml would be assumed to be on the
  85. classpath whereasfile:dir/file.xml would use the file system.
  86. Any valid URL string issupported.
  87. </description>
  88. <config-property-name>BrokerXmlConfig</config-property-name>
  89. <config-property-type>java.lang.String</config-property-type>
  90. <!--<config-property-value></config-property-value>-->
  91. <config-property-value>xbean:broker-config.xml</config-property-value>
  92. <!--
  93. To use the broker-config.xml fromthe root for the RAR
  94. To use an external file or urllocation
  95. <config-property-value>xbean:file:///amq/config/jee/broker-config.xml</config-property-value>
  96. -->
  97. </config-property>
  98. <outbound-resourceadapter>
  99. <connection-definition>
  100. <managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>
  101. <connectionfactory-interface>javax.jms.ConnectionFactory</connectionfactory-interface>
  102. <connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>
  103. <connection-interface>javax.jms.Connection</connection-interface>
  104. <connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>
  105. </connection-definition>
  106. <connection-definition>
  107. <managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>
  108. <connectionfactory-interface>javax.jms.QueueConnectionFactory</connectionfactory-interface>
  109. <connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>
  110. <connection-interface>javax.jms.QueueConnection</connection-interface>
  111. <connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>
  112. </connection-definition>
  113. <connection-definition>
  114. <managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>
  115. <connectionfactory-interface>javax.jms.TopicConnectionFactory</connectionfactory-interface>
  116. <connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>
  117. <connection-interface>javax.jms.TopicConnection</connection-interface>
  118. <connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>
  119. </connection-definition>
  120. <transaction-support>XATransaction</transaction-support>
  121. <authentication-mechanism>
  122. <authentication-mechanism-type>BasicPassword</authentication-mechanism-type>
  123. <credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>
  124. </authentication-mechanism>
  125. <reauthentication-support>false</reauthentication-support>
  126. </outbound-resourceadapter>
  127. <inbound-resourceadapter>
  128. <messageadapter>
  129. <messagelistener>
  130. <messagelistener-type>javax.jms.MessageListener</messagelistener-type>
  131. <activationspec>
  132. <activationspec-class>org.apache.activemq.ra.ActiveMQActivationSpec</activationspec-class>
  133. <required-config-property>
  134. <config-property-name>destination</config-property-name>
  135. </required-config-property>
  136. <required-config-property>
  137. <config-property-name>destinationType</config-property-name>
  138. </required-config-property>
  139. </activationspec>
  140. </messagelistener>
  141. </messageadapter>
  142. </inbound-resourceadapter>
  143. <adminobject>
  144. <adminobject-interface>javax.jms.Queue</adminobject-interface>
  145. <adminobject-class>org.apache.activemq.command.ActiveMQQueue</adminobject-class>
  146. <config-property>
  147. <config-property-name>PhysicalName</config-property-name>
  148. <config-property-type>java.lang.String</config-property-type>
  149. </config-property>
  150. </adminobject>
  151. <adminobject>
  152. <adminobject-interface>javax.jms.Topic</adminobject-interface>
  153. <adminobject-class>org.apache.activemq.command.ActiveMQTopic</adminobject-class>
  154. <config-property>
  155. <config-property-name>PhysicalName</config-property-name>
  156. <config-property-type>java.lang.String</config-property-type>
  157. </config-property>
  158. </adminobject>
  159. </resourceadapter>
  160. </connector>

6.        配置 activemq (2):修改 broker-config.xml 文件

[html] view plaincopy

print?

  1. <?xmlversionxmlversion="1.0"encoding="UTF-8"?>
  2. <!--
  3. Licensed to the Apache Software Foundation(ASF) under one or more
  4. contributor license agreements.  See the NOTICE file distributed with
  5. this work for additional informationregarding copyright ownership.
  6. The ASF licenses this file to You under theApache License, Version 2.0
  7. (the "License"); you may not usethis file except in compliance with
  8. the License.  You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreedto in writing, software
  11. distributed under the License isdistributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.
  13. See the License for the specific languagegoverning permissions and
  14. limitations under the License.
  15. -->
  16. <!--START SNIPPET: xbean -->
  17. <beans
  18. xmlns="http://www.springframework.org/schema/beans"
  19. xmlns:amq="http://activemq.apache.org/schema/core"
  20. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  21. xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  22. http://activemq.apache.org/schema/corehttp://activemq.apache.org/schema/core/activemq-core.xsd">
  23. <!-- shutdown hook is disabled as RAR classloader may be gone at shutdown-->
  24. <brokerxmlnsbrokerxmlns="http://activemq.apache.org/schema/core"useJmx="true"useShutdownHook="false"brokerName="bruce.broker1">
  25. <managementContext>
  26. <!-- use appserver provided contextinstead of creating one,
  27. for jboss use:-Djboss.platform.mbeanserver -->
  28. <managementContextcreateConnectormanagementContextcreateConnector="false"/>
  29. </managementContext>
  30. <persistenceAdapter>
  31. <kahaDBdirectorykahaDBdirectory="activemq-data/kahadb"/>
  32. <!--<jdbcPersistenceAdapterdataSource="#oracle-ds"/>-->
  33. </persistenceAdapter>
  34. <transportConnectors>
  35. <transportConnectornametransportConnectorname="bruce.broker1"uri="tcp://localhost:61616"/>
  36. </transportConnectors>
  37. </broker>
  38. </beans>

7.        配置 jboss5,使得jboss5启动的时候能够启动activemq

新建 /default/deploy/activemq-ds.xml 文件,内容如下:

[html] view plaincopy

print?

  1. <?xmlversionxmlversion="1.0"encoding="UTF-8"?>
  2. <!DOCTYPEconnection-factories
  3. PUBLIC "-//JBoss//DTD JBOSS JCA Config5.0//EN"
  4. "http://www.jboss.org/j2ee/dtd/jboss-ds_5_0.dtd">
  5. <connection-factories>
  6. <tx-connection-factory>
  7. <jndi-name>activemq/QueueConnectionFactory</jndi-name>
  8. <xa-transaction/>
  9. <track-connection-by-tx/>
  10. <rar-name>activemq-ra-5.7.0.rar</rar-name>
  11. <connection-definition>javax.jms.QueueConnectionFactory</connection-definition>
  12. <ServerUrl>vm://localhost</ServerUrl>
  13. <!--
  14. <UserName>sa</UserName>
  15. <Password></Password>
  16. -->
  17. <min-pool-size>1</min-pool-size>
  18. <max-pool-size>200</max-pool-size>
  19. <blocking-timeout-millis>30000</blocking-timeout-millis>
  20. <idle-timeout-minutes>3</idle-timeout-minutes>
  21. </tx-connection-factory>
  22. <tx-connection-factory>
  23. <jndi-name>activemq/TopicConnectionFactory</jndi-name>
  24. <xa-transaction/>
  25. <track-connection-by-tx/>
  26. <rar-name>activemq-ra-5.7.0.rar</rar-name>
  27. <connection-definition>javax.jms.TopicConnectionFactory</connection-definition>
  28. <ServerUrl>vm://localhost</ServerUrl>
  29. <!--
  30. <UserName>sa</UserName>
  31. <Password></Password>
  32. -->
  33. <min-pool-size>1</min-pool-size>
  34. <max-pool-size>200</max-pool-size>
  35. <blocking-timeout-millis>30000</blocking-timeout-millis>
  36. <idle-timeout-minutes>3</idle-timeout-minutes>
  37. </tx-connection-factory>
  38. <mbeancodembeancode="org.jboss.resource.deployment.AdminObject"name="activemq.queue:name=outboundQueue">
  39. <attributenameattributename="JNDIName">activemq/queue/outbound</attribute>
  40. <dependsoptional-attribute-namedependsoptional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra-5.7.0.rar'</depends>
  41. <attributenameattributename="Type">javax.jms.Queue</attribute>
  42. <attributenameattributename="Properties">PhysicalName=queue.outbound</attribute>
  43. </mbean>
  44. <mbeancodembeancode="org.jboss.resource.deployment.AdminObject"name="activemq.topic:name=inboundTopic">
  45. <attributenameattributename="JNDIName">activemq/topic/inbound</attribute>
  46. <dependsoptional-attribute-namedependsoptional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra-5.7.0.rar'</depends>
  47. <attributenameattributename="Type">javax.jms.Topic</attribute>
  48. <attributenameattributename="Properties">PhysicalName=topic.inbound</attribute>
  49. </mbean>
  50. </connection-factories>

8.        启动 jboss5

9.        验证集成成功与否

a)        安装ANT

b)        配置ANT环境变量

c)        启动JBOSS

d)        打开一个命令窗口,输入

cd /apache-activemq-5.3.1/example

ant consumer

e)        打开另外一个命令窗口,输入:

cd /apache-activemq-5.3.1/example

ant consumer

10.    运行成功

JBOSS5+ActiveMQ5.7集成相关推荐

  1. springboot的细节挖掘(ActiveMq集成)

    官网下载地址: http://activemq.apache.org/?utm_source=csdn_toolbar 下载的时候区别:ActiveMQ 5 "Classic"和A ...

  2. Nignx集成fastDFS后访问Nginx一直在加载中解决

    问题描述: Nginx集成fastDFS后,访问Nginx一直在加载中,得不到页面.查看Nginx的错误日志: 可以看到是fastdfs.conf的配置错误,tracker的ip没有修改: fastd ...

  3. Hexo集成Algolia实现搜索功能

    2年前搭建的hexo博客好久没有维护了,一看 hexo 以及先前使用 butterfly 主题已经更新好几个版本了,看介绍在速度性能上有了很大的提高,于是打算给 hexo 升个级,整理整理翻翻新.通过 ...

  4. 将TVM集成到PyTorch

    将TVM集成到PyTorch 随着TVM不断展示出对深度学习执行效率的改进,很明显PyTorch将从直接利用编译器堆栈中受益.PyTorch的主要宗旨是提供无缝且强大的集成,而这不会妨碍用户.PyTo ...

  5. 将TVM集成到PyTorch上

    将TVM集成到PyTorch上 随着TVM不断展示出对深度学习执行效率的改进,很明显PyTorch将从直接利用编译器堆栈中受益.PyTorch的主要宗旨是提供无缝且强大的集成,而这不会妨碍用户.为此, ...

  6. Vitis-AI集成

    Vitis-AI集成 Vitis-AI是Xilinx的开发堆栈,用于在Xilinx平台(包括边端设备和Alveo卡)上进行硬件加速的AI推理.它由优化的IP,工具,库,模型和示例设计组成.设计时考虑到 ...

  7. 中继TensorRT集成

    中继TensorRT集成 介绍 NVIDIA TensorRT是用于优化深度学习推理的库.这种集成将使尽可能多的算子从Relay转移到TensorRT,从而无需调整调度,即可在NVIDIA GPU上提 ...

  8. 如何在TVM上集成Codegen(下)

    如何在TVM上集成Codegen(下) Bring DNNL to TVM: JSON Codegen/Runtime 现在实现将Relay,序列化为JSON表示的DNNL codegen,然后实现D ...

  9. 如何在TVM上集成Codegen(上)

    如何在TVM上集成Codegen(上) 许多常用的深度学习内核,或者提供DNNL或TensorRT等框架和图形引擎,让用户以某种方式描述模型,从而获得高性能.此外,新兴的深度学习加速器也有自己的编译器 ...

最新文章

  1. Vue.js 源码分析(二十三) 指令篇 v-show指令详解
  2. unity android eclipse,[转]Android笔记:Eclipse嵌入Unity3D开发的3D场景
  3. 【Python爬虫学习笔记6】JSON文件存储
  4. [LintCode] Wildcard Matching
  5. (JAVA学习笔记) 关于i++和++i的区别
  6. TensorFlow和ML前5名的课程
  7. 放弃Eclipse Juno
  8. 【Matplotlib】【Python】如何使用matplotlib颜色映射
  9. python函数执行顺序_python下for循环接if判断的函数执行顺序
  10. crfpp python
  11. iOS开发之开源项目链接
  12. jmeter无法启动的解决办法
  13. 数据AES加密安全传输之后台JAVA加密解密
  14. php+美图秀秀,美图秀秀web开放平台--PHP流式上传和表单上传示例分享
  15. UG NX 12 内部草图和外部草图的区别
  16. 摄氏度符号英文计算机语言,温度表示-摄氏度怎样用英文表示温度?给几个例子,好吗? 爱问知识人...
  17. android studio实现动画,android studio上的基本动画实现(第一篇)
  18. 正规蓝牙耳机一般多少钱?音质好又便宜的蓝牙耳机
  19. 感动,我终于学会了用Java对数组求和
  20. 创建多线程有几种方法?如何创建线程?

热门文章

  1. Python基础:文件的操作
  2. LLVM 4中将加入新的LLVM链接器LLD
  3. 在centos6.5中安装reids
  4. 【1138】数据结构上机测试2-1:单链表操作A(顺序建表+删除节点)(SDUT)
  5. MySQL数据库性能优化之硬件瓶颈分析
  6. Office 365强势来袭PART3:管理云用户
  7. Kubernetes 的CRI-O容器引擎中存在严重漏洞
  8. 苹果修复被 XCSSET 恶意软件滥用的3个 0day
  9. Google Update Service 被曝提权 0day,谷歌拒绝修复
  10. 护航敏捷开发和运维 BCS2020举办DevSecOps论坛