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

标签 java jakarta-ee wildfly wildfly-10

我有两个 JMS 服务器,它们在独立的全 HA 环境中作为 JMS 集群链接在一起。这些服务器正在托管我的 JMS-Destination(我们称它们为 JMS-Master)。

此外,还有一个配置为独立完整服务器的服务器(我们将其命名为 JMS-Slave)。该服务器有一个到 JMS 主题的 JMS 桥。

对于此配置,我在 JMS-Slave 上创建了两个到远程服务器的套接字绑定(bind):

<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 桥:

<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 主服务器都已启动并且我启动了 JMS 从服务器, 一切正常。
  • 如果其中一台 JMS-Master 服务器已关闭并且我启动了 JMS-Slave,它会 也有效。 jms-bridge 连接到可用节点。
  • 但是如果我关闭 JMS-Slave 的 JMS 桥接的节点 已连接,没有故障转移。

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

我怎样才能实现这个目标?是否有其他可能性获得类似的行为?或者是否有一个完全不同的设置的建议?

最佳答案

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

第一个是使用 JMS-Core-Bridge。请参阅Configuring Core Bridges at the Red Hat JBoss docs :

Do not confuse a core bridge with a JMS bridge. A core bridge is used to bridge any two JBoss EAP messaging instances and uses the core API. A JMS bridge can be used to bridge any two JMS 1.1 compliant JMS providers and uses the JMS API. It is preferable to use a core bridge instead of a JMS bridge whenever possible.

核心桥或多或少可以开箱即用地进行故障转移。只要有一个连接器,它就会自动进行故障转移。它在第一次连接期间检索集群拓扑并在其生命周期内使用它。为了能够在 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 桥,使其重新连接到另一台服务器。为了建立连接,JMS 桥在属性“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/

相关文章:

java - Spring 使用@Validated 验证 Controller

java - 框架和按钮

java - JPA如何获取持久化对象自动生成的ID?

java - 统计Hibernate中多对多表中ID的出现次数

java - Wildfly 无法注入(inject)值(value)?

java - 将代码移入包后出现 UnsatisfiedLinkError

java - RequestDispatcher.forward循环

jakarta-ee - Liferay 7 Service Builder 不会自动更新数据库

JBoss(Wildfly 10.0) 上的 Java Web 应用程序未通过 Eclipse 部署

SSL SAN 证书无法解析备用名称