是否可以使用Wildfly 10为JMS-Bridge配置故障转移到JMS-Cluster?

时间:2018-02-01 10:58:45

标签: java java-ee wildfly wildfly-10

我有两个JMS-Servers在一个独立的全ha环境中作为JMS-Cluster链接在一起。这些服务器托管我的JMS-Destinations(让我们称之为JMS-Master)。

此外,还有一个服务器配置为独立服务器(让我们将其命名为JMS-Slave)。该服务器具有JMS-Bridge到JMS-Topic。

对于这个配置,我在JMS-Slave创建了两个套接字绑定到远程服务器:

<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-Slave的JMS Bridge的节点 连接没有故障转移。

我正在寻找一种配置,其中JMS-Bridge在崩溃后“重新连接”到可用节点,而没有将它放入与JMS-Master相同的集群中。

我怎样才能做到这一点?是否有其他可能获得类似的行为?或者是否有建议进行完全不同的设置?

1 个答案:

答案 0 :(得分:1)

我想我自己找到了两个可能解决问题的方法。但它们都有一些缺点。

第一个是使用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-Queues似乎没有开销。

但是也可以配置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主服务器的连接器,则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配置”的缺点是它的复杂性。

相关问题