我有两个JMS服务器,它们在独立的全ha环境中作为JMS群集链接在一起。这些服务器托管着我的JMS目的地(我们称它们为JMS-Master)。
此外,还有一台服务器配置为独立的完整服务器(将其命名为JMS-Slave)。该服务器具有到JMS主题的JMS桥。
对于此配置,我在JMS从站上创建了两个到远程服务器的套接字绑定:
<outbound-socket-binding name="remote-server-1">
<remote-destination host="a.b.c.d" port="8080"/>
</outbound-socket-binding>
<outbound-socket-binding name="remote-server-2">
<remote-destination host="a.b.c.d" port="18080"/>
</outbound-socket-binding>
我在消息传递子系统配置的两个http连接器上使用它们:
<http-connector name="remote-1-http-connector" socket-binding="remote-server-1" endpoint="http-acceptor"/>
<http-connector name="remote-2-http-connector" socket-binding="remote-server-2" endpoint="http-acceptor"/>
我创建了一个池连接工厂:
<pooled-connection-factory name="remote-connection" entries="java:/jms/remoteCF" connectors="remote-1-http-connector remote-2-http-connector" user="testuser" password="testpassword" failover-on-initial-connection="true"/>
最后,我配置了JMS-Bridge:
<jms-bridge name="HelloWorldQueue-jms-bridge" quality-of-service="DUPLICATES_OK" failure-retry-interval="5000" max-retries="-1" max-batch-size="10" max-batch-time="100">
<source connection-factory="ConnectionFactory" destination="queue/HelloWorldQueue"/>
<target connection-factory="jms/RemoteConnectionFactory" destination="queue/HelloWorldQueue" user="heinz" password="becker" >
<target-context>
<property name="java.naming.factory.initial" value="org.jboss.naming.remote.client.InitialContextFactory"/>
<property name="java.naming.provider.url" value="http-remoting://a.b.c.d:8080, http-remoting://a.b.c.d:18080"/>
</target-context>
</target>
</jms-bridge>
结果:
如果两个JMS-Master服务器都已启动,并且我启动了JMS-Slave,
一切正常。
如果其中一台JMS-Master服务器已关闭,而我启动了JMS-Slave,则它将
也可以。 jms-bridge连接到可用节点。
但是,如果我关闭了JMS从站的JMS桥所连接的节点
已连接,没有故障转移。
我正在寻找一种配置,其中JMS-Bridge在崩溃到可用节点后会“重新连接”,而不会与JMS-Master处于同一群集中。
我该如何实现?还有其他可能得到类似的行为吗?还是有一个建议使用完全不同的设置?
最佳答案
我想我自己找到了两种可能的解决方案。但是它们都有一些缺点。
第一个是使用JMS-Core-Bridge。参见Configuring Core Bridges at the Red Hat JBoss docs:
不要将核心桥与JMS桥混淆。使用核心桥
桥接任何两个JBoss EAP消息传递实例并使用核心API。
JMS桥可用于桥接任何两个符合JMS 1.1的JMS
提供程序并使用JMS API。最好使用芯桥
尽可能使用JMS桥。
Core-Bridge开箱即用地进行故障转移。使用一个连接器已经可以自动进行故障转移。它在第一次连接时检索集群拓扑,并在其生命周期内使用它。为了能够在JMS-Master关闭时启动网桥,我们可以添加其他连接器:
<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
<server name="default">
....
<bridge name="my-core-bridge" static-connectors="remote-1-http-connector remote-2-http-connector" queue-name="jms.queue.HelloWorldQueue" user="username" password="pwd"/>
</server>
...
</subsystem>
核心网桥的缺点似乎是它不立即支持JMS-Topics。只有JMS队列似乎没有开销。
但是也可以配置重新连接到另一台服务器的JMS-Bridge。为了建立连接,JMS-Bridge在由属性“ java.naming.provider.url”配置的其中一台服务器上进行JNDI查找。此查找只是在启动过程中执行的,一旦完成,它将使用检索到的远程连接工厂(此处称为RemoteConnectionFactory)进行连接和重新连接。但是它正在使用JMS-Master的RemoteConnectionFactory!因此有必要
在此处配置此连接工厂:
<connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="master-1-http-connector master-2-http-connector" ha="true" block-on-acknowledge="true" reconnect-attempts="-1"/>
如果此RemoteConnectionFactory有一个到每个JMS-Master的连接器,则JMS-Bridge检索所有必要的信息以在必要时重新连接到另一台服务器。我的问题的桥配置现在无需修改即可工作:
<jms-bridge name="HelloWorldQueue-jms-bridge" quality-of-service="DUPLICATES_OK" failure-retry-interval="5000" max-retries="-1" max-batch-size="10" max-batch-time="100">
<source connection-factory="ConnectionFactory" destination="queue/HelloWorldQueue"/>
<target connection-factory="jms/RemoteConnectionFactory" destination="queue/HelloWorldQueue" user="username" password="pwd" >
<target-context>
<property name="java.naming.factory.initial" value="org.jboss.naming.remote.client.InitialContextFactory"/>
<property name="java.naming.provider.url" value="http-remoting://a.b.c.d:8080, http-remoting://a.b.c.d:18080"/>
</target-context>
</target>
</jms-bridge>
我的“ jms-bridge配置”的缺点是它的复杂性。
关于java - 是否可以使用Wildfly 10为JMS-Bridge配置故障转移到JMS-Cluster?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48561115/