我正在通过下面的 context.xml 在 Tomcat 中创建嵌入式 ActiveMQ。它指定代理 url brokerURL="vm://localhost?brokerConfig=xbean:activemq.xml"
中的配置 xml 位置。 .
我已经把activemq.xml
在我的 WAR 文件的底部(所以就在 WAR 中 WEB-INF 的旁边)。在那里能找到吗?
MyWAR.war
WEB-INF/
beans.xml
activemq.xml
我的 context.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- JMS Factory and Queue -->
<Resource auth="Container"
name="jms/ConnectionFactory"
type="org.apache.activemq.ActiveMQConnectionFactory"
description="JMS Connection Factory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
brokerURL="vm://localhost?brokerConfig=xbean:activemq.xml"
brokerName="MyBroker"
useEmbeddedBroker="true"
trustAllPackages="true"
persistent="true"
/>
<Resource auth="Container"
name="jms/MyQueue"
type="org.apache.activemq.command.ActiveMQQueue"
description="Downtime Event JMS queue"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
physicalName="MyQueue"
persistent="true"
/>
<Resource auth="Container"
name="jms/MyQueueRetry"
type="org.apache.activemq.command.ActiveMQQueue"
description="Downtime Event JMS queue"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
physicalName="MyQueueRetry"
persistent="true"
/>
</Context>
编辑:我更新的 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.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<bean id="ioExceptionHandler" class="org.apache.activemq.util.DefaultIOExceptionHandler">
<property name="ignoreAllErrors"><value>true</value></property>
</bean>
<!-- MySql DataSource Sample Setup -->
<bean id="mysql-ds" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.0.0.1:3306/activemq"/>
<property name="username" value="testuser"/>
<property name="password" value="password"/>
<property name="poolPreparedStatements" value="true"/>
</bean>
<broker
xmlns="http://activemq.apache.org/schema/core"
persistent="true"
ioExceptionHandler="#ioExceptionHandler"
useShutdownHook="true"
useJmx="false"
brokerName="EventBroker"
>
<persistenceAdapter>
<jdbcPersistenceAdapter dataSource="#mysql-ds" />
</persistenceAdapter>
</broker>
</beans>
我还尝试了以下两种方法:
brokerURL="vm://localhost?brokerConfig=xbean:classpath:activemq.xml"
(并将其放入WEB-INF中)
brokerURL="vm://localhost?brokerConfig=xbean:classpath:WEB-INF/activemq.xml"
它从不使用 MySQL。
最佳答案
几种方法..
将 org.apache.activemq 的日志记录提高到 DEBUG 或 TRACE
在开放端口 61618 上添加一个附加条目。使用 netstat 确认它正在监听。
此外,您还可以连接到正在运行的 JVM 进程的 JMX,并查看存在的 org.apache.activemq JMX beans。
一些引用资料:
关于java - 我如何知道 ActiveMQ 是否正在使用我的 activemq.xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44792956/