我有一个Jboss EAP 6.3实例,其中托管了HornetQ主题(jndi - " java:jboss / exported / jms / topic / TestTopic"所以应远程可见)我还有另一个实例(比如说)客户端)部署到相同的Jboss版本。我必须使用@MessageDriven方法从客户端收听TestTopic。我google了很多,但我仍然不知道如何指定与远程主机的连接来收听该主题。 我找到了一个使用@ActivationConfigProperty的例子(propertyName =" connectionParameters",propertyValue =" host = SOME_HOST; port = SOME_PORT"),但该属性未在规范中指定,似乎没有影响力。
迄今为止的事务: standalone.xml的一部分:
<subsystem xmlns="urn:jboss:domain:messaging:1.4">
<hornetq-server>
<persistence-enabled>true</persistence-enabled>
<journal-type>NIO</journal-type>
<journal-min-files>2</journal-min-files>
<connectors>
<netty-connector name="netty" socket-binding="messaging"/>
<netty-connector name="netty-throughput" socket-binding="messaging-throughput">
<param key="batch-delay" value="50"/>
</netty-connector>
<in-vm-connector name="in-vm" server-id="0"/>
</connectors>
<acceptors>
<netty-acceptor name="netty" socket-binding="messaging"/>
<netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">
<param key="batch-delay" value="50"/>
<param key="direct-deliver" value="false"/>
</netty-acceptor>
<in-vm-acceptor name="in-vm" server-id="0"/>
</acceptors>
<security-settings>
<security-setting match="#">
<permission type="send" roles="guest"/>
<permission type="consume" roles="guest"/>
<permission type="createNonDurableQueue" roles="guest"/>
<permission type="deleteNonDurableQueue" roles="guest"/>
</security-setting>
</security-settings>
<address-settings>
<address-setting match="#">
<dead-letter-address>jms.queue.DLQ</dead-letter-address>
<expiry-address>jms.queue.ExpiryQueue</expiry-address>
<redelivery-delay>0</redelivery-delay>
<max-size-bytes>10485760</max-size-bytes>
<page-size-bytes>2097152</page-size-bytes>
<address-full-policy>PAGE</address-full-policy>
<message-counter-history-day-limit>10</message-counter-history-day-limit>
</address-setting>
</address-settings>
<jms-connection-factories>
<connection-factory name="InVmConnectionFactory">
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/ConnectionFactory"/>
</entries>
</connection-factory>
<connection-factory name="RemoteConnectionFactory">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
</entries>
</connection-factory>
<pooled-connection-factory name="hornetq-ra">
<transaction mode="xa"/>
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/JmsXA"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>
<jms-destinations>
<jms-queue name="ExpiryQueue">
<entry name="java:/jms/queue/ExpiryQueue"/>
</jms-queue>
<jms-queue name="DLQ">
<entry name="java:/jms/queue/DLQ"/>
</jms-queue>
<jms-topic name="TestTopic">
<entry name="java:/jms/topic/TestTopic"/>
<entry name="java:jboss/exported/jms/topic/TestTopic"/>
</jms-topic>
</jms-destinations>
</hornetq-server>
</subsystem>
和我的bean设置
@MessageDriven(mappedName = "TestTopicRemote", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/exported/jms/topic/TestTopic"),
@ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/RemoteConnectionFactory"),
@ActivationConfigProperty(propertyName = "clientId", propertyValue = "guest"),
@ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "host=MY_HOST;port=5445")})
答案 0 :(得分:1)
最终我解决了这个问题。也许对某人有帮助:事实上,standalone.xml不需要额外的更改。 MDB必须如下所示:
@MessageDriven(mappedName = "TestTopicRemote", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "TestTopic"),
@ActivationConfigProperty(propertyName = "connectorClassName", propertyValue = "${jms.topic.connectorClassName}"),
@ActivationConfigProperty(propertyName = "user", propertyValue = "${jms.topic.user}"),
@ActivationConfigProperty(propertyName = "password", propertyValue = "${jms.topic.password}"),
@ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "${jms.topic.connectionParameters}")})
这里${SOMETHING}
是standalone.xml中定义的系统属性(为了使这个工作成为一个标志&#34; annotation-property-replacement&#34;在standalone.xml中必须为true):
<system-properties>
<property name="jms.topic.connectorClassName" value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"/>
<property name="jms.o.user" value="USERNAME"/>
<property name="jms.o.password" value="PASSWORD"/>
<property name="jms.o.connectionParameters" value="host=YOUR_HOST;port=5445"/>
</system-properties>
注意用户USERNAME必须存在于接收服务器上。如果说Jboss,则必须将应用程序用户添加到来宾组(此角色具有发送和接收消息的默认权限)
当然,设置属性是可选的,我这样做只是为了避免硬编码
答案 1 :(得分:0)
检查您是否必须在MDB上提供@ResourceAdapter(value =&#34; activemq-rar-5.6.0.rar&#34;)注释。我在看我的,我看到除了@MessageDriven之外,所有的MDB都带有这个标签。
另外standalone.xml应该具有到服务器和端口的连接信息 我的standalone.xml有activeMQ服务器URL
答案 2 :(得分:0)
在使用JBoss EAP 6.4的集群环境中失败。例如,Foo.war在群集中部署两次,然后由于重复的客户端ID,第二个MDB将无法注册。如果您使客户端ID唯一,则MDB的两个实例都将收到该消息。
目前,我没有解决方法。