整合ActiveMQ和JBoss
1,实验准备
ActiveMQ4.1.1
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文件,修改配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<connector xmlns="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>ActiveMQ inbound and outbound JMS ResourceAdapter</description>
<display-name>ActiveMQ JMS Resource Adapter</display-name>
<vendor-name>activemq.org</vendor-name>
<eis-type>JMS 1.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>
The URL to the ActiveMQ server that you want this connection to connect to. If using
an embedded broker, this value should be '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>The default user name that will be used to establish connections to the ActiveMQ server.</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>The default password that will be used to log the default user into the ActiveMQ server.</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>The client id that will be set on the connection that is established to the ActiveMQ server.</description>
<config-property-name>Clientid</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>
<config-property>
<description>Boolean to configure if outbound connections should reuse the inbound connection's session for sending messages.</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>
<!-- NOTE disable the following property if you do not wish to deploy an embedded broker -->
<config-property>
<description>
Sets the XML configuration file used to configure the embedded ActiveMQ broker via
Spring if using embedded mode.
BrokerXmlConfig is the filename which is assumed to be on the classpath unless
a URL is specified. So a value of foo/bar.xml would be assumed to be on the
classpath whereas file:dir/file.xml would use the file system.
Any valid URL string is supported.
</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文件,修改配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<!-- START SNIPPET: xbean -->
<beans>
<broker useJmx="true" brokerName="bruce.broker1" xmlns="http://activemq.org/config/1.0">
<!-- In ActiveMQ 4, you can setup destination policies. note: this xml format may still change a bit -->
<destinationPolicy>
<policyMap><policyEntries>
<policyEntry topic="FOO.>">
<dispatchPolicy>
<strictOrderDispatchPolicy />
</dispatchPolicy>
<subscriptionRecoveryPolicy>
<lastImageSubscriptionRecoveryPolicy />
</subscriptionRecoveryPolicy>
</policyEntry>
</policyEntries></policyMap>
</destinationPolicy>
<persistenceAdapter>
<journaledJDBC journalLogFiles="5" dataDirectory="activemq-data"/>
<!-- To use a different datasource, use th following syntax : -->
<!--
<journaledJDBC journalLogFiles="5" dataDirectory="../data" dataSource="#postgres-ds"/>
-->
</persistenceAdapter>
<transportConnectors>
<!-- prefixing a connector with discovery: causes the connector to be advertiesed over rendezvous -->
<transportConnector name="bruce.broker1" uri="tcp://localhost:61616" discoveryUri="multicast://default"/>
</transportConnectors>
<networkConnectors>
<!-- by default just auto discover the other brokers -->
<networkConnector uri="multicast://default"/>
<!--
<networkConnector uri="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文件,添加内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE connection-factories
PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.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>
<mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.queue:name=outboundQueue">
<attribute name="JNDIName">activemq/queue/outbound</attribute>
<depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
<attribute name="Type">javax.jms.Queue</attribute>
<attribute name="Properties">PhysicalName=queue.outbound</attribute>
</mbean>
<mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.topic:name=inboundTopic">
<attribute name="JNDIName">activemq/topic/inbound</attribute>
<depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
<attribute name="Type">javax.jms.Topic</attribute>
<attribute name="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 整合篇(也是有些小错误,需要和上面的文档结合起来才能成功)。
作者:洞庭散人
出处:http://phinecos.cnblogs.com/
posted on 2007-06-09 11:13 Phinecos(洞庭散人) 阅读(4437) 评论(1) 编辑 收藏 举报