1,实验准备
ActiveMQ4.1.1,jboss-4.0.5.GA,Ant 1.7.0
2,安装jboss到D:/jboss,bin/run来启动jboss,打开http://localhost:8080/web-console/测试是否安装成功。
3,安装ActiveMQ到D:/activemq,启动activeMQ测试是否安装成功。
4,在D:/jboss/server/default/deploy下面创建activemq-ra.rar目录,将D:/activemq/lib/optional/activemq-rar-4.1.1解压缩到这个目录下。
5.打开D:/jboss/server/default/deploy/activemq-ra.rar/META-INF下的ra.xml文件,修改配置如下:
ra.xml
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><?xmlversion="1.0"encoding="UTF-8"?>
<connectorxmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
version="1.5">
<description>ActiveMQinboundandoutboundJMSResourceAdapter</description>
<display-name>ActiveMQJMSResourceAdapter</display-name>
<vendor-name>activemq.org</vendor-name>
<eis-type>JMS1.1</eis-type>
<resourceadapter-version>1.0</resourceadapter-version>
<license>
<license-required>true</license-required>
</license>
<resourceadapter>
<resourceadapter-class>org.apache.activemq.ra.ActiveMQResourceAdapter</resourceadapter-class>
<config-property>
<description>
TheURLtotheActiveMQserverthatyouwantthisconnectiontoconnectto.Ifusing
anembeddedbroker,thisvalueshouldbe'vm://localhost'.
</description>
<config-property-name>ServerUrl</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<!--<config-property-value>tcp://localhost:61616</config-property-value>-->
<config-property-value>vm://localhost</config-property-value>
</config-property>
<config-property>
<description>ThedefaultusernamethatwillbeusedtoestablishconnectionstotheActiveMQserver.</description>
<config-property-name>UserName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>defaultUser</config-property-value>
</config-property>
<config-property>
<description>ThedefaultpasswordthatwillbeusedtologthedefaultuserintotheActiveMQserver.</description>
<config-property-name>Password</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>defaultPassword</config-property-value>
</config-property>
<config-property>
<description>TheclientidthatwillbesetontheconnectionthatisestablishedtotheActiveMQserver.</description>
<config-property-name>Clientid</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>
<config-property>
<description>Booleantoconfigureifoutboundconnectionsshouldreusetheinboundconnection'ssessionforsendingmessages.</description>
<config-property-name>UseInboundSession</config-property-name>
<config-property-type>java.lang.Boolean</config-property-type>
<config-property-value>false</config-property-value>
</config-property>
<!--NOTEdisablethefollowingpropertyifyoudonotwishtodeployanembeddedbroker-->
<config-property>
<description>
SetstheXMLconfigurationfileusedtoconfiguretheembeddedActiveMQbrokervia
Springifusingembeddedmode.
BrokerXmlConfigisthefilenamewhichisassumedtobeontheclasspathunless
aURLisspecified.Soavalueoffoo/bar.xmlwouldbeassumedtobeonthe
classpathwhereasfile:dir/file.xmlwouldusethefilesystem.
AnyvalidURLstringissupported.
</description>
<config-property-name>BrokerXmlConfig</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<!--<config-property-value></config-property-value>-->
<config-property-value>xbean:broker-config.xml</config-property-value>
</config-property>
<outbound-resourceadapter>
<connection-definition>
<managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>
<connectionfactory-interface>javax.jms.ConnectionFactory</connectionfactory-interface>
<connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>
<connection-interface>javax.jms.Connection</connection-interface>
<connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>
</connection-definition>
<connection-definition>
<managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>
<connectionfactory-interface>javax.jms.QueueConnectionFactory</connectionfactory-interface>
<connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>
<connection-interface>javax.jms.QueueConnection</connection-interface>
<connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>
</connection-definition>
<connection-definition>
<managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>
<connectionfactory-interface>javax.jms.TopicConnectionFactory</connectionfactory-interface>
<connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>
<connection-interface>javax.jms.TopicConnection</connection-interface>
<connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>
</connection-definition>
<transaction-support>XATransaction</transaction-support>
<authentication-mechanism>
<authentication-mechanism-type>BasicPassword</authentication-mechanism-type>
<credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>
</authentication-mechanism>
<reauthentication-support>false</reauthentication-support>
</outbound-resourceadapter>
<inbound-resourceadapter>
<messageadapter>
<messagelistener>
<messagelistener-type>javax.jms.MessageListener</messagelistener-type>
<activationspec>
<activationspec-class>org.apache.activemq.ra.ActiveMQActivationSpec</activationspec-class>
<required-config-property>
<config-property-name>destination</config-property-name>
</required-config-property>
<required-config-property>
<config-property-name>destinationType</config-property-name>
</required-config-property>
</activationspec>
</messagelistener>
</messageadapter>
</inbound-resourceadapter>
<adminobject>
<adminobject-interface>javax.jms.Queue</adminobject-interface>
<adminobject-class>org.apache.activemq.command.ActiveMQQueue</adminobject-class>
<config-property>
<config-property-name>PhysicalName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>
</adminobject>
<adminobject>
<adminobject-interface>javax.jms.Topic</adminobject-interface>
<adminobject-class>org.apache.activemq.command.ActiveMQTopic</adminobject-class>
<config-property>
<config-property-name>PhysicalName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>
</adminobject>
</resourceadapter>
</connector>
6,打开D:/jboss/server/default/deploy/activemq-ra.rar/
broker-config.xml文件,修改配置如下:
broker-config.xml
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><?xmlversion="1.0"encoding="UTF-8"?>
<!--STARTSNIPPET:xbean-->
<beans>
<brokeruseJmx="true"brokerName="bruce.broker1"xmlns="http://activemq.org/config/1.0">
<!--InActiveMQ4,youcansetupdestinationpolicies.note:thisxmlformatmaystillchangeabit-->
<destinationPolicy>
<policyMap><policyEntries>
<policyEntrytopic="FOO.>">
<dispatchPolicy>
<strictOrderDispatchPolicy/>
</dispatchPolicy>
<subscriptionRecoveryPolicy>
<lastImageSubscriptionRecoveryPolicy/>
</subscriptionRecoveryPolicy>
</policyEntry>
</policyEntries></policyMap>
</destinationPolicy>
<persistenceAdapter>
<journaledJDBCjournalLogFiles="5"dataDirectory="activemq-data"/>
<!--Touseadifferentdatasource,usethfollowingsyntax:-->
<!--
<journaledJDBCjournalLogFiles="5"dataDirectory="../data"dataSource="#postgres-ds"/>
-->
</persistenceAdapter>
<transportConnectors>
<!--prefixingaconnectorwithdiscovery:causestheconnectortobeadvertiesedoverrendezvous-->
<transportConnectorname="bruce.broker1"uri="tcp://localhost:61616"discoveryUri="multicast://default"/>
</transportConnectors>
<networkConnectors>
<!--bydefaultjustautodiscovertheotherbrokers-->
<networkConnectoruri="multicast://default"/>
<!--
<networkConnectoruri="static://(tcp://host1:61616,tcp://host2:61616)"/>
-->
</networkConnectors>
</broker>
</beans>
7,启动jboss验证是否配置成功,如果没有报错就可以了。
8,配置jboss让activeMQ能跟随jboss启动。在D:/jboss/server/default/deploy下新建activemq-jms-ds.xml文件,添加内容如下:
activemq-jms-ds.xml
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEconnection-factories
PUBLIC"-//JBoss//DTDJBOSSJCAConfig1.5//EN"
"http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
<connection-factories>
<tx-connection-factory>
<jndi-name>activemq/QueueConnectionFactory</jndi-name>
<xa-transaction/>
<track-connection-by-tx/>
<rar-name>activemq-ra.rar</rar-name>
<connection-definition>javax.jms.QueueConnectionFactory</connection-definition>
<ServerUrl>vm://localhost</ServerUrl>
<!--
<UserName>sa</UserName>
<Password></Password>
-->
<min-pool-size>1</min-pool-size>
<max-pool-size>200</max-pool-size>
<blocking-timeout-millis>30000</blocking-timeout-millis>
<idle-timeout-minutes>3</idle-timeout-minutes>
</tx-connection-factory>
<tx-connection-factory>
<jndi-name>activemq/TopicConnectionFactory</jndi-name>
<xa-transaction/>
<track-connection-by-tx/>
<rar-name>activemq-ra.rar</rar-name>
<connection-definition>javax.jms.TopicConnectionFactory</connection-definition>
<ServerUrl>vm://localhost</ServerUrl>
<!--
<UserName>sa</UserName>
<Password></Password>
-->
<min-pool-size>1</min-pool-size>
<max-pool-size>200</max-pool-size>
<blocking-timeout-millis>30000</blocking-timeout-millis>
<idle-timeout-minutes>3</idle-timeout-minutes>
</tx-connection-factory>
<mbeancode="org.jboss.resource.deployment.AdminObject"name="activemq.queue:name=outboundQueue">
<attributename="JNDIName">activemq/queue/outbound</attribute>
<dependsoptional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
<attributename="Type">javax.jms.Queue</attribute>
<attributename="Properties">PhysicalName=queue.outbound</attribute>
</mbean>
<mbeancode="org.jboss.resource.deployment.AdminObject"name="activemq.topic:name=inboundTopic">
<attributename="JNDIName">activemq/topic/inbound</attribute>
<dependsoptional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
<attributename="Type">javax.jms.Topic</attribute>
<attributename="Properties">PhysicalName=topic.inbound</attribute>
</mbean>
</connection-factories>
9,再次启动jboss验证配置是否成功。
10,测试activemq是否已经跟随jboss启动了。打开二个命令窗口,第一个进入D:/activemq/example,输入:ant consumer,第二个进入D:/activemq/example,输入ant producer,如果成功发送/接收了消息,OK,一切搞定。
11,参考文献:
1)Integrating
Apache ActiveMQ with JBoss(但是里面有些小错误,照做的话没有成功)
2)ActiveMQ 实践之路(三) ActiveMQ 4.x +JBoss 4.x 整合篇(也是有些小错误,需要和上面的文档结合起来才能成功)。
分享到:
相关推荐
springboot整合activemq案例,queue,topic两种模式 定时运行和controller请求运行两种方式
Spring整合ActiveMQ实现队列和主题发布订阅通信、一个完整的DEMO
博客http://blog.csdn.net/poorCoder_/article/details/61192791的代码。Spring整合ActiveMQ的简单实例
springboot整合 activeMq 消费者 消费接收消息 包含队列模式点对点发 以及 主题模式一对多 这是消费者的demo consumer 。 里面有消息重发机制,手动确认ACK模式。 配合 producer 生产者demo使用。
springboot整合 activeMq 生产者 发送消息 包含队列模式点对点发送消息 以及 主题模式一对多发送消息 这是生产者的demo producer; 需要配合消费者的demo consumer 使用
springboot整合ActiveMQ源码,适合范围消息队列入门小伙伴,对ActiveMQ消息队列不太了解,不知道如何发送消息,接收消息可以围观。
Spring Boot 做的一个简单的增删改查,前台页面整合Thymeleaf模板,数据源druid,声明式事务,整合redis,并开启redis事务,整合ActiveMQ
源码为web工程,整合了Spring,SpringMVC、ActiveMQ,启动后,index页面输入消息,控制台输出消息。
百度spring整合activemq 发现几乎都只是在xml文件配置固定的消息队列而且太麻烦。并没有根据需求进行动态生成主题和队列。本文档参考了纯粹的activemq java代码和百度上的demo,很简洁的实现了动态消息队列的生成和...
JMS教程+activemq以及activemq和tomcat的整合+整合实例代码+持久化消息配置以及工程+tomcat服务器的配置
详细内容: SpringJMS整合ActiveMQ.doc 详细说明文档 apache-activemq-5.8.0-bin.zip ActiveMQ安装包 JMSTest.rar MyEclipse8.5下web工程
Spring和ActiveMQ整合的完整实例
spring整合activemq的maven工程 activemq+spring+maven project
SpringBoot整合ActiveMQ+websocket.docx ,该文档包含于activemq整合的各个情况,springboot,js,websocket与mq整合,该资源是上传代码的word文档部分
Sping整合ActiveMq案例,利用Maven的坐标技术整合Sping技术实现消息生产者发送消息通过消息中间件,然后消息消费者消费消息
SpringBoot整合ActiveMQ简单案例 1.包含apache-activemq-5.15.3-bin.zip 2.生产者项目 3.消费者项目
java springboot整合activemq工程 #activemq配置 #默认情况下activemq提供的是queue模式 true是可以使用topic,false是仅使用queue模式 spring.jms.pub-sub-domain: true # 设置连接的activemq服务器 spring....
Springboot和ActiveMQ的整合实例
SpringBoot整合ActiveMQ消息队列和双向队列、点对点与发布订阅,可以参考我的博客文章进行学习https://blog.csdn.net/sujin_/article/details/82956386
与我写的博客配套的,springboot整合activemq的项目实例,看我写的博客,在搭配实例可以非常快速的学会并使用avtivemq。 在先学习整合之前先了解一下ActiaveMQ,ActiveMQ是早期MQ产品之一,是使用JAVA语言编写。大...