`
phinecos
  • 浏览: 342351 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

整合ActiveMQ和JBoss

 
阅读更多

1,实验准备


ActiveMQ4.1.1

,jboss-4.0.5.GA

,Ant 1.7.0

2,安装jbossD:/jbossbin/run来启动jboss,打开http://localhost:8080/web-console/测试是否安装成功。

3,安装ActiveMQD:/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,配置jbossactiveMQ能跟随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,参考文献:

1Integrating Apache ActiveMQ with JBoss(但是里面有些小错误,照做的话没有成功)

2ActiveMQ 实践之路() ActiveMQ 4.x +JBoss 4.x 整合(也是有些小错误,需要和上面的文档结合起来才能成功)。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics