【问题标题】:EAP 7 JMS cluster not in sync. Scheduled JMS message blocked when node is downEAP 7 JMS 集群不同步。节点关闭时阻止计划的 JMS 消息
【发布时间】:2019-06-17 20:18:33
【问题描述】:

我正在以独立模式设置 EAP 7 集群。我关注this tutorial 并设置了我的集群。

然后我开始使用一个简单的 JMS 应用程序测试 JMS 系统。每次发送 JMS 消息时,我观察到 JMS 消息计数仅在一个节点中更新(而不是视频中显示的两个节点)。发送的消息总数等于来自两个节点的计数之和。

但是,由于节点是集群的,我希望 JMS 统计信息是同步的(视频中显示),因此两个节点都应该显示集群中接收到的消息总数,而不是只显示其中的一部分。

另外,在发送预定消息时,如果持有该消息的节点死亡,则该消息被阻塞,直到该死节点重新启动。这绝对是不可接受的,因为我希望计划的消息由另一个(正在运行的)节点传递。

所有测试均使用默认的standalone-full-ha.xml 执行

以下是重现问题的所有步骤:

环境设置

  1. 下载eap7.1/7.2或wildfly12/14并解压到一个目录
  2. 将目录重命名为 my-dir-node1
  3. 将 your-dir-node1 复制到 my-dir-node2
  4. 更新配置
    1. 转到 my-dir-node1/standalone 并将standalone-full-ha.xml 复制到standalone-full-ha-test.xml
    2. 编辑 my-dir-node1/standalone/standalone-full-ha-test.xml
    3. 将 name="node1" 添加到根元素:<server xmlns="urn:jboss:domain:5.0" name="node1">
    4. 搜索<cluster password="${jboss.messaging.cluster.password:CHANGE ME!!}"/>并将其替换为<cluster password="${jboss.messaging.cluster.password:mypassword}"/>
    5. 在<jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/> 之后添加<jms-queue name="JMSTest" entries="java:/jms/queue/test"/>
    6. 转到 my-dir-node2/standalone 并重复上述步骤。确保将其命名为服务器“node2”而不是“node1”

通过将 test-jms.war 复制到 my-dir-node1/standalone/deploy 和 your-dir-node2/standalone/deploy 来部署测试应用

我的测试应用的内容

<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.jms.*" %>
<%@ page import="java.util.logging.Logger" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%

    Logger logger = Logger.getLogger("JMSSender");
    InitialContext initialContext = new InitialContext();
    ConnectionFactory factory = (ConnectionFactory) initialContext.lookup("ConnectionFactory");
    Destination destination = (Destination)initialContext.lookup("java:/jms/queue/test");
    Connection connection = factory.createConnection();
    Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer messageProducer = session1.createProducer(destination);

    String body = request.getParameter("message");

    if (body == null)
        body = "Hello World!";

    TextMessage message = session1.createTextMessage(body);

    String delay = request.getParameter("delay");

    if (delay != null)
        message.setJMSDeliveryTime(System.currentTimeMillis() + Integer.parseInt(delay));

    messageProducer.send(message);

    logger.info("Send message: " + body);
%>
<html>
  <head>
    <title>Test JMS Sender</title>
  </head>
  <body>
  <h1>Message</h1>
  <p><strong><%=body%></strong></p>
  <p>Add ?message=xxx to the url to change the message.</p>
  <p>Add ?delay=xxx to the url to schedule a delivery at a later time. The unit of delay is in millisecond. ie: 1 second = 1000 </p>
  </body>
</html>

JMS 接收器:

import org.apache.log4j.Logger;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

@MessageDriven(mappedName = "testQueue", activationConfig =  {
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
        , @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
        , @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/queue/test")
})
public class JMSReceiver implements MessageListener {

    // Logger for the class
    private static Logger logger = Logger.getLogger(JMSReceiver.class.getName());

    @Override
    public void onMessage(Message message) {
        TextMessage t = (TextMessage) message;
        try {
            logger.info(t.getText());
        } catch (JMSException e) {
            logger.info(e.getMessage());
        }
    }
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

【问题讨论】:

    标签: jms jboss-eap-7 activemq-artemis


    【解决方案1】:

    您对 EAP 中的消息传递集群(以及您链接的视频)的理解不正确。如果您向 EAP 中的消息传递集群发送 1 消息,则集群中唯一的 1 节点具有该消息。消息不会在集群中的所有节点之间复制。集群中每个节点的 JMS 统计信息不一定是同步的。

    您所看到的实际上是预期的行为。此外,这是您链接的视频中演示的内容。在视频中,客户端应用程序每次运行都会发送 2 条消息。一条消息发送到一个集群节点,第二条消息发送到另一个集群节点。这就是为什么每个节点上的“添加的消息”指标会增加并且似乎是同步的。当发送 2 条消息 (1+1=2) 时,每个节点上的“已添加消息”指标增加 1。集群中添加到队列中的消息总数可以通过对集群中每个节点的“添加的消息”求和来确定。

    了解此行为很重要,因为这意味着如果集群中的某个节点出现故障,则该节点上的所有消息都将变得不可用(如您所见)。如果您希望消息在节点故障的情况下可用,那么您需要配置实时/备份对。有关如何完成此操作的更多详细信息,请咨询EAP documentation。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-14
      • 2019-09-06
      • 2013-05-30
      • 1970-01-01
      • 2013-03-23
      • 1970-01-01
      • 2017-02-22
      相关资源
      最近更新 更多