在 Wildfly 中,监听外部 ActiveMQ 的 MDB 得到一个空的 JMSMessageId
In Wildfly, MDB listening to external ActiveMQ gets a null JMSMessageId
我正在测试 Wildfly16 / JBoss 7.2 与 ActiveMQ Artemis 2.7 的连接性。
我写了一个简单的MDB,它可以使用来自远程ActiveMQ Artemis 服务器的消息。
我正确获取了payload(短信)和CorrelationId,但是收到的MessageId为空!这看起来很奇怪而且很烦人,因为我想实现 request/reply.
- 为了启用从 Wildfly 到外部 ActiveMQ Artemis 服务器的访问,我按照 31.3. Configuring the Artemis Resource Adapter to Connect to Red Hat JBoss AMQ 7 中指示的步骤进行操作。成功了。
- 我创建了一个简单的 Java 客户端,它能够直接 send/consume/browse 队列。当我使用此客户端使用消息时,我会得到 MessageId、CorrelationId 和我期望的所有内容。
- 问题出现在 Wildfly 16、17 和 JBoss 7.2 上的消息驱动 Bean(我都试过了)。
- 我部署在Wildfly上的MDB的Jar没有依赖(6Kb)
MDB代码下方
import java.util.Properties;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.ejb3.annotation.ResourceAdapter;
@ResourceAdapter("activemq-ra-remote")
@MessageDriven(name = "JmsTestMDB", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "testReqQueue"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
public class WildflyMdb implements MessageListener {
private static final Logger LOGGER = Logger.getLogger(WildflyMdb.class.toString());
public void onMessage(Message rcvMessage) {
TextMessage txtMessage = null;
try {
if (rcvMessage instanceof TextMessage) {
txtMessage = (TextMessage) rcvMessage;
LOGGER.info("Received Message from queue: MessageId=" + rcvMessage.getJMSMessageID() +
", CorrelationId=" + rcvMessage.getJMSCorrelationID() +
", Text='" + txtMessage.getText() + "'");
LOGGER.info("rcvMessage (toString): " + rcvMessage.toString());
} catch (Exception e) {
LOGGER.severe("EXCEPTION:" + e.getMessage());
}
}
当我向 Java 客户端发送以下消息时:
- 消息 ID:ID:DEVTEMP-PC-49242-1561392550500-1:1:1:1:1
- CorrelationId:CID:20190624180910
- 短信:'This is my test message'
我从 Wildfly 的 MDB 中得到以下日志:
16:23:29,694 INFO [class com.fluide.mdb.WildflyMdb] (Thread-360 (ActiveMQ-client-global-threads)) Received Message from queue: MessageId=null, CorrelationId=CID:20190624180910, Text='This is my test message'
16:23:29,695 INFO [class com.fluide.mdb.WildflyMdb] (Thread-360 (ActiveMQ-client-global-threads)) rcvMessage (toString): ActiveMQMessage[null]:PERSISTENT/ClientMessageImpl[messageID=946860, durable=true, address=testReqQueue,userID=null,properties=TypedProperties[__AMQ_CID=ID:DEVTEMP-PC-49242-1561392550500-0:1,_AMQ_GROUP_SEQUENCE=0,__HDR_BROKER_IN_TIME=1561392550749,_AMQ_ROUTING_TYPE=1,__HDR_ARRIVAL=0,__HDR_REPLY_TO=[0000 0011 6401 000D 7465 7374 5265 7370 5175 6575 65),__HDR_COMMAND_ID=5,JMSCorrelationID=CID:20190624180910,__HDR_PRODUCER_ID=[0000 0039 7B01 0025 4944 3A44 4556 5445 4D50 2D50 432D 3439 3234 322D 3135 ... 31 3339 3235 3530 3530 302D 313A 3100 0000 0000 0000 0100 0000 0000 0000 01),__HDR_MESSAGE_ID=[0000 004C 6E00 017B 0100 2549 443A 4445 5654 454D 502D 5043 2D34 3932 3432 ... 0000 0000 0001 0000 0000 0000 0001 0000 0000 0000 0001 0000 0000 0000 0000),__HDR_DROPPABLE=false]]
如您所见,MessageId
returns 为 null 看起来不正确。
有什么想法吗?
EAP 7.2 在 Artemis 2.x 上,因此您不必那样做。您可以在子系统级别使用配置良好的简单 pooled-connection-factory :http://wildscribe.github.io/WildFly/16.0/subsystem/messaging-activemq/pooled-connection-factory/index.html
由于您使用来自 activemq-all-5.12.0.jar
的 OpenWire 协议通过独立 Java 客户端发送消息,并使用 Artemis 核心协议在 Wildfly/EAP 上通过 MDB 接收消息 I相信您在 ActiveMQ Artemis 中点击了 this bug,这会导致使用不同协议发送和接收的消息的消息 ID 为空。 pull-request 已发送,因此该问题应在 2.10.0 中得到解决。
如果您不想等待 2.10.0 发布,那么您可以 work-around 通过使用独立 Java 应用程序中的 Artemis 核心 JMS 客户端实现来解决问题。只需放入 Artemis 客户端 jar(从 /lib/client 目录)并将初始上下文工厂更改为 org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
.
我正在测试 Wildfly16 / JBoss 7.2 与 ActiveMQ Artemis 2.7 的连接性。
我写了一个简单的MDB,它可以使用来自远程ActiveMQ Artemis 服务器的消息。
我正确获取了payload(短信)和CorrelationId,但是收到的MessageId为空!这看起来很奇怪而且很烦人,因为我想实现 request/reply.
- 为了启用从 Wildfly 到外部 ActiveMQ Artemis 服务器的访问,我按照 31.3. Configuring the Artemis Resource Adapter to Connect to Red Hat JBoss AMQ 7 中指示的步骤进行操作。成功了。
- 我创建了一个简单的 Java 客户端,它能够直接 send/consume/browse 队列。当我使用此客户端使用消息时,我会得到 MessageId、CorrelationId 和我期望的所有内容。
- 问题出现在 Wildfly 16、17 和 JBoss 7.2 上的消息驱动 Bean(我都试过了)。
- 我部署在Wildfly上的MDB的Jar没有依赖(6Kb)
MDB代码下方
import java.util.Properties;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.ejb3.annotation.ResourceAdapter;
@ResourceAdapter("activemq-ra-remote")
@MessageDriven(name = "JmsTestMDB", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "testReqQueue"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
public class WildflyMdb implements MessageListener {
private static final Logger LOGGER = Logger.getLogger(WildflyMdb.class.toString());
public void onMessage(Message rcvMessage) {
TextMessage txtMessage = null;
try {
if (rcvMessage instanceof TextMessage) {
txtMessage = (TextMessage) rcvMessage;
LOGGER.info("Received Message from queue: MessageId=" + rcvMessage.getJMSMessageID() +
", CorrelationId=" + rcvMessage.getJMSCorrelationID() +
", Text='" + txtMessage.getText() + "'");
LOGGER.info("rcvMessage (toString): " + rcvMessage.toString());
} catch (Exception e) {
LOGGER.severe("EXCEPTION:" + e.getMessage());
}
}
当我向 Java 客户端发送以下消息时:
- 消息 ID:ID:DEVTEMP-PC-49242-1561392550500-1:1:1:1:1
- CorrelationId:CID:20190624180910
- 短信:'This is my test message'
我从 Wildfly 的 MDB 中得到以下日志:
16:23:29,694 INFO [class com.fluide.mdb.WildflyMdb] (Thread-360 (ActiveMQ-client-global-threads)) Received Message from queue: MessageId=null, CorrelationId=CID:20190624180910, Text='This is my test message'
16:23:29,695 INFO [class com.fluide.mdb.WildflyMdb] (Thread-360 (ActiveMQ-client-global-threads)) rcvMessage (toString): ActiveMQMessage[null]:PERSISTENT/ClientMessageImpl[messageID=946860, durable=true, address=testReqQueue,userID=null,properties=TypedProperties[__AMQ_CID=ID:DEVTEMP-PC-49242-1561392550500-0:1,_AMQ_GROUP_SEQUENCE=0,__HDR_BROKER_IN_TIME=1561392550749,_AMQ_ROUTING_TYPE=1,__HDR_ARRIVAL=0,__HDR_REPLY_TO=[0000 0011 6401 000D 7465 7374 5265 7370 5175 6575 65),__HDR_COMMAND_ID=5,JMSCorrelationID=CID:20190624180910,__HDR_PRODUCER_ID=[0000 0039 7B01 0025 4944 3A44 4556 5445 4D50 2D50 432D 3439 3234 322D 3135 ... 31 3339 3235 3530 3530 302D 313A 3100 0000 0000 0000 0100 0000 0000 0000 01),__HDR_MESSAGE_ID=[0000 004C 6E00 017B 0100 2549 443A 4445 5654 454D 502D 5043 2D34 3932 3432 ... 0000 0000 0001 0000 0000 0000 0001 0000 0000 0000 0001 0000 0000 0000 0000),__HDR_DROPPABLE=false]]
如您所见,MessageId
returns 为 null 看起来不正确。
有什么想法吗?
EAP 7.2 在 Artemis 2.x 上,因此您不必那样做。您可以在子系统级别使用配置良好的简单 pooled-connection-factory :http://wildscribe.github.io/WildFly/16.0/subsystem/messaging-activemq/pooled-connection-factory/index.html
由于您使用来自 activemq-all-5.12.0.jar
的 OpenWire 协议通过独立 Java 客户端发送消息,并使用 Artemis 核心协议在 Wildfly/EAP 上通过 MDB 接收消息 I相信您在 ActiveMQ Artemis 中点击了 this bug,这会导致使用不同协议发送和接收的消息的消息 ID 为空。 pull-request 已发送,因此该问题应在 2.10.0 中得到解决。
如果您不想等待 2.10.0 发布,那么您可以 work-around 通过使用独立 Java 应用程序中的 Artemis 核心 JMS 客户端实现来解决问题。只需放入 Artemis 客户端 jar(从 org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
.