我如何在 Wildfly 中通过 MDB 远程接收消息?
How can i receive messages through an MDB remotely in Wildfly?
我在不同的机器上有两台 Wildfly 服务器 运行,其中一台将向另一台发送 JMS 消息。我创建了一个简单的测试应用程序,它似乎在发送消息,但另一端没有接收到。事实上它已经在抱怨它无法连接:
14:17:21,188 WARN [org.hornetq.jms.server] (MSC service thread 1-6) HQ122018: Could not start recovery discovery on XARecoveryConfig [transportConfiguration = [TransportConfiguration(name=ca25380b-c270-11e4-ac81-876cdf81429b, factory=org-hornetq-core-remoting-impl-netty-NettyConnectorFactory) ?port=5545&host=192-168-179-25&local-address=127-0-0-1], discoveryConfiguration = null, username=null, password=****], we will retry every recovery scan until the server is available
14:17:21,296 INFO [org.hornetq.ra] (default-threads - 1) HQ151005: awaiting HornetQ Server availability
14:17:23,300 INFO [org.hornetq.ra] (default-threads - 1) HQ151001: Attempting to reconnect org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@6d148215 destination=jms/queue/myqueue destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15)
我在配置两台服务器时尝试了很多方法。生产服务器的部分配置:
<subsystem xmlns="urn:jboss:domain:messaging:2.0">
<hornetq-server>
<connectors>
<netty-connector name="netty" socket-binding="messaging"/>
</connectors>
<acceptors>
<netty-acceptor name="netty" socket-binding="messaging"/>
</acceptors>
<jms-connection-factories>
<pooled-connection-factory name="hornetq-ra">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="java:/JmsXA"/>
<entry name="java:jboss/DefaultJMSConnectionFactory"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>
<jms-destinations>
<jms-queue name="myQueue">
<entry name="java:jboss/exported/jms/queue/myqueue"/>
<entry name="java:/jms/queue/myqueue"/>
</jms-queue>
</jms-destinations>
</hornetq-server>
</subsystem>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
<socket-binding name="messaging" port="5445"/>
</socket-binding-group>
和消费服务器的:
<subsystem xmlns="urn:jboss:domain:messaging:2.0">
<hornetq-server>
<connectors>
<netty-connector name="netty" socket-binding="messaging-remote"/>
</connectors>
<acceptors>
<netty-acceptor name="netty" socket-binding="messaging"/>
</acceptors>
<jms-connection-factories>
<pooled-connection-factory name="hornetq-ra">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="java:/JmsXA"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>
<jms-destinations>
<jms-queue name="myQueue">
<entry name="java:/jms/queue/myqueue"/>
</jms-queue>
</jms-destinations>
</hornetq-server>
</subsystem>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
<socket-binding name="messaging" port="5445"/>
<outbound-socket-binding name="messaging-remote">
<remote-destination host="192.168.179.25" port="5545"/>
</outbound-socket-binding>
</socket-binding-group>
希望有人能给我一个提示。我感觉这应该很容易。
我设法让它工作了。一些要点:
- 消费服务器配置中的消息传递远程端口当然应该指向与生产服务器 (5445) 中相同的端口。
需要使用bin/add-user.sh工具创建用户。然后 MDB 需要两个 ActivationConfigProperty:
@ActivationConfigProperty(propertyName = "user", propertyValue = "jms"),
@ActivationConfigProperty(propertyName = "password", propertyValue = "password")
非常重要的是,standalone-full.xml配置默认只允许本地流量,所以你必须在生产服务器中重新配置public接口:
<interface name="public">
<any-address/>
</interface>
或者稍微宽松一些。
我在不同的机器上有两台 Wildfly 服务器 运行,其中一台将向另一台发送 JMS 消息。我创建了一个简单的测试应用程序,它似乎在发送消息,但另一端没有接收到。事实上它已经在抱怨它无法连接:
14:17:21,188 WARN [org.hornetq.jms.server] (MSC service thread 1-6) HQ122018: Could not start recovery discovery on XARecoveryConfig [transportConfiguration = [TransportConfiguration(name=ca25380b-c270-11e4-ac81-876cdf81429b, factory=org-hornetq-core-remoting-impl-netty-NettyConnectorFactory) ?port=5545&host=192-168-179-25&local-address=127-0-0-1], discoveryConfiguration = null, username=null, password=****], we will retry every recovery scan until the server is available
14:17:21,296 INFO [org.hornetq.ra] (default-threads - 1) HQ151005: awaiting HornetQ Server availability
14:17:23,300 INFO [org.hornetq.ra] (default-threads - 1) HQ151001: Attempting to reconnect org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@6d148215 destination=jms/queue/myqueue destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15)
我在配置两台服务器时尝试了很多方法。生产服务器的部分配置:
<subsystem xmlns="urn:jboss:domain:messaging:2.0">
<hornetq-server>
<connectors>
<netty-connector name="netty" socket-binding="messaging"/>
</connectors>
<acceptors>
<netty-acceptor name="netty" socket-binding="messaging"/>
</acceptors>
<jms-connection-factories>
<pooled-connection-factory name="hornetq-ra">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="java:/JmsXA"/>
<entry name="java:jboss/DefaultJMSConnectionFactory"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>
<jms-destinations>
<jms-queue name="myQueue">
<entry name="java:jboss/exported/jms/queue/myqueue"/>
<entry name="java:/jms/queue/myqueue"/>
</jms-queue>
</jms-destinations>
</hornetq-server>
</subsystem>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
<socket-binding name="messaging" port="5445"/>
</socket-binding-group>
和消费服务器的:
<subsystem xmlns="urn:jboss:domain:messaging:2.0">
<hornetq-server>
<connectors>
<netty-connector name="netty" socket-binding="messaging-remote"/>
</connectors>
<acceptors>
<netty-acceptor name="netty" socket-binding="messaging"/>
</acceptors>
<jms-connection-factories>
<pooled-connection-factory name="hornetq-ra">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="java:/JmsXA"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>
<jms-destinations>
<jms-queue name="myQueue">
<entry name="java:/jms/queue/myqueue"/>
</jms-queue>
</jms-destinations>
</hornetq-server>
</subsystem>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
<socket-binding name="messaging" port="5445"/>
<outbound-socket-binding name="messaging-remote">
<remote-destination host="192.168.179.25" port="5545"/>
</outbound-socket-binding>
</socket-binding-group>
希望有人能给我一个提示。我感觉这应该很容易。
我设法让它工作了。一些要点:
- 消费服务器配置中的消息传递远程端口当然应该指向与生产服务器 (5445) 中相同的端口。
需要使用bin/add-user.sh工具创建用户。然后 MDB 需要两个 ActivationConfigProperty:
@ActivationConfigProperty(propertyName = "user", propertyValue = "jms"), @ActivationConfigProperty(propertyName = "password", propertyValue = "password")
非常重要的是,standalone-full.xml配置默认只允许本地流量,所以你必须在生产服务器中重新配置public接口:
<interface name="public"> <any-address/> </interface>
或者稍微宽松一些。