在Tomcat中集成ActiveMQ

tomcat版本:6.0.20
activeMQ版本:5.2

网上有一些介绍,但是很多都是采用JNDI的方式,麻烦,而且tomcat和activemq要分别启动,理想的方式是启动tomcat的同时启动activemq,在web工程中直接使用activemq

1,新建web工程,并导入基本jar包
[img]http://dl.iteye.com/upload/attachment/222359/9b93d71b-97da-37ff-a3f7-e4454e0bf51c.jpg[/img]
2,修改web.xml
<context-param>
<param-name>brokerURI</param-name>
<param-value>/WEB-INF/activemq.xml</param-value>
</context-param>

<listener>
<listener-class>org.apache.activemq.web.SpringBrokerContextListener</listener-class>
</listener>

3,增加WEB-INF/activemq.xml
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.2.0.xsd
http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">

<!-- The Oracle Datasource that will be used by the Broker -->
<bean id="oracle-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
<property name="username" value="activemq"/>
<property name="password" value="neusoft"/>
<property name="maxActive" value="200"/>
<property name="poolPreparedStatements" value="true"/>
</bean>

<!-- ==================================================================== -->
<!-- ActiveMQ Broker Configuration -->
<!-- ==================================================================== -->
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost">
<!-- The store and forward broker networks ActiveMQ will listen to -->
<networkConnectors>
<!-- by default just auto discover the other brokers -->
<networkConnector name="default-nc" uri="multicast://default"/>
<!-- Example of a static configuration:
<networkConnector name="host1 and host2" uri="static://(tcp://host1:61616,tcp://host2:61616)"/>
-->
</networkConnectors>

<!--
to enable Stomp support uncomment this <connector> <serverTransport
uri="stomp://localhost:61626"/> </connector>
-->

<persistenceAdapter>
<jdbcPersistenceAdapter dataSource="#oracle-ds"/>
<journaledJDBC useDatabaseLock="false"></journaledJDBC>
</persistenceAdapter>


<transportConnectors>
<transportConnector name="openwire" uri="tcp://localhost:61616" discoveryUri="multicast://default"/>
<transportConnector name="xmpp" uri="xmpp://localhost:61222"/>
</transportConnectors>
</broker>

</beans>


OK,将web工程添加进tomcat,启动tomcat,大功告成。

注意事项:
1,导入的基本jar包,只保证能够提供activemq的基本服务。
2,使用数据库来存储activemq的message,也可以不使用。
3,本文使用数据库为oracle,其他数据库的配置请参照下载zip的activemq.xml
4,如此配置activemq,启动的时候必须连接网线,否则会报错。
5,activemq.xml中的<journaledJDBC useDatabaseLock="false"></journaledJDBC>是保证更换数据库的时候activemq依然能够顺利启动
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值