我在 JBoss 5.1.2 中运行的 MDB 通过 JMS 连接到远程独立 HornetQ 时遇到问题。我知道 HornetQ 已经启动并且运行良好,因为我可以连接到它并通过 HermesJMS 放置/查看消息。但是,我的实际应用似乎无法成功连接到它。
这是我的@MessageDriven 注释:
@MessageDriven(
messageListenerInterface = MessageListener.class,
activationConfig = {
@ActivationConfigProperty( //type of destination we pull messages from
propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty( //which destination JNDI suffix we pull message from
propertyName = "destination", propertyValue = "queue/inputQueue"),
@ActivationConfigProperty( //how many times to reattempt on service errors
propertyName = "dLQMaxResent", propertyValue = "1"),
@ActivationConfigProperty( //how many seconds to try a reconnect when failure to connect to jms provider
propertyName = "reconnectInterval", propertyValue = "15"),
@ActivationConfigProperty(
propertyName = "providerAdapterJNDI", propertyValue = "java:/RemoteJMSProvider")
}
)
这是我的 jms-ds.xml 文件中的配置:
<mbean code="org.jboss.jms.jndi.JMSProviderLoader"
name="hornetq:service=MSProviderLoader,name=RemoteJMSProvider,server=remotehost">
<attribute name="ProviderName">RemoteJMSProvider</attribute>
<attribute name="ProviderAdapterClass">org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
<!-- The connection factory -->
<attribute name="FactoryRef">/LocalHornetQConnectionFactory</attribute>
<!-- The queue connection factory -->
<attribute name="QueueFactoryRef">/LocalHornetQConnectionFactory</attribute>
<!-- The topic factory -->
<attribute name="TopicFactoryRef">/LocalHornetQConnectionFactory</attribute>
<!-- Connect to JNDI on the host "the-remote-host-name" port 1099-->
<attribute name="Properties">
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=IPADDRESS:1099
</attribute> </mbean>
我可以在 JBoss jmx-console 中查看 RemoteJMSProvider。此外,在 JNDIView 中,我可以看到远程 JMS 提供者的 JNDI 名称。我还可以在 JMX 控制台中看到 jms.queue.inputQueue,但是当我尝试查看其上的消息时,它说没有消息,即使我通过查看 HermesJMS 知道有消息。
最后,在我的应用程序中没有例外。一切似乎都运行良好,但它从未收到任何消息。甚至 HornetQ 日志也显示我的 IP 地址已连接,所以我不确定为什么我无法读取队列:
[RMI TCP Connection(6)-10.3.78.123] 17:02:06,837 FINER [sun.rmi.transport.tcp] RMI TCP Connection(6)-10.3.78.123: (port 1098) client using 10.3.78.123:0
有任何想法吗?
这是我的HornetQ(2.2.5)配置信息供参考。
hornetq-jms.xml:
<connection-factory name="LocalHornetQConnectionFactory">
<xa>true</xa>
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="/LocalHornetQConnectionFactory"/>
</entries>
<retry-interval>5000</retry-interval>
<retry-interval-multiplier>1.0</retry-interval-multiplier>
<reconnect-attempts>-1</reconnect-attempts>
<failover-on-server-shutdown>true</failover-on-server-shutdown>
<confirmation-window-size>1048576</confirmation-window-size>
</connection-factory>
<queue name="invalidQueue">
<entry name="/queue/invalidQueue"/>
</queue>
<queue name="inputQueue">
<entry name="/queue/inputQueue"/>
</queue>
<queue name="errorQueue">
<entry name="/queue/errorQueue"/>
</queue>
<topic name="SAFEStorageAcknowledgement">
<entry name="/topic/SAFEStorageAcknowledgement"/>
</topic>
<topic name="SAFEEvents">
<entry name="/topic/SAFEEvents"/>
</topic>
hornetq-configuration.xml:
<address-settings>
<!--default for catch all-->
<address-setting match="#">
<dead-letter-address>jms.queue.errorQueue</dead-letter-address>
<expiry-address>jms.queue.errorQueue</expiry-address>
<redelivery-delay>15000</redelivery-delay>
<max-size-bytes>10485760</max-size-bytes>
<message-counter-history-day-limit>10</message-counter-history-day-limit>
<address-full-policy>BLOCK</address-full-policy>
<redistribution-delay>60000</redistribution-delay>
</address-setting>
</address-settings>
<queues>
<queue name="jms.queue.inputQueue">
<address>jms.queue.inputQueue</address>
</queue>
<queue name="jms.queue.errorQueue">
<address>jms.queue.errorQueue</address>
</queue>
<queue name="jms.queue.invalidQueue">
<address>jms.queue.invalidQueue</address>
</queue>
</queues>
所有其他 HornetQ 设置都是默认设置。
谢谢,安迪