使用 Wildlfy 11 嵌入式 Apache Artemis 接收 MQTT 消息
Receiving MQTT message with Wildlfy 11 embedded Apache Artemis
我想在带有嵌入式 Apache Artemis 的 Wildfly 11 中接收 MQTT 消息。
当前状态:
我为 Wildfly 嵌入式 Apache Artemis 添加了 MQTT 协议支持(添加了 "missing" 文件夹和 artemis-mqtt-protocol-.jar 并在 module.xml)
我正在使用完整的独立配置并为 MTQQ 添加了接受器:
<subsystem xmlns="urn:jboss:domain:messaging-activemq:2.0">
<server name="default">
<remote-acceptor name="mqtt-acceptor" socket-binding="mqtt">
<param name="protocols" value="MQTT"/>
</remote-acceptor>
主题为:
<jms-topic name="testEndpoint" entries="java:/jms/testEndpoint"/>
- 还添加了 mqtt 到套接字绑定
从日志中我可以看到它有效:
AMQ221020: Started Acceptor at 127.0.0.1:1883 for protocols [MQTT]
AMQ221007: Server is now live AMQ221001: Apache ActiveMQ Artemis
Message Broker version 1.5.5.jbossorg-008
AMQ221003: Deploying queue jms.queue.DLQ
WFLYMSGAMQ0002: Bound messaging object to jndi name
java:/ConnectionFactory
AMQ221003: Deploying queue jms.queue.ExpiryQueue
WFLYMSGAMQ0002: Bound messaging object to jndi name
java:jboss/exported/jms/RemoteConnectionFactory
AMQ221052: Deploying topic jms.topic.testEndpoint
- 接下来我写了一个简单的MDB为:
@MessageDriven(
activationConfig = { @ActivationConfigProperty(propertyName = "destination",
propertyValue = "testEndpoint"),
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Topic")
},
mappedName = "testEndpoint")
public class TestEndpoint implements MessageListener {
private static final Logger logger = Logger.getLogger(TestEndpoint.class.getName());
public void onMessage(Message message) {
try {
logger.debug("message: " + message.getClass().getName());
} catch (Exception e) {
logger.debug("exception: " + e.getMessage());
}
}
}
- 我可以连接到端口 1883 上的服务器,当我向 testEndpoint 发送消息时,我可以在日志中看到:
SESSION CREATED: 63f14f85-0fa2-4fe7-a27b-03ef8e6639a2
Couldn't find any bindings for address=testEndpoint on
message=ServerMessage[messageID=962,durable=true,userID=null,priority=0,
bodySize=512, timestamp=0,expiration=0, durable=true,
address=testEndpoint,properties=TypedProperties[mqtt.message.retain=true,mqtt.qos.level=1]]@749653273
Message
ServerMessage[messageID=962,durable=true,userID=null,priority=0,
bodySize=512, timestamp=0,expiration=0, durable=true,
address=testEndpoint,properties=TypedProperties[mqtt.message.retain=true,mqtt.qos.level=1]]@749653273 is not going anywhere as it didn't have a binding on
address:testEndpoint
QueueImpl[name=$sys.mqtt.retain.testEndpoint,
postOffice=PostOfficeImpl
[server=ActiveMQServerImpl::serverUUID=c58c74d5-ea71-11e7-9621-a434d929f4aa]]@6ff93fb4
doing deliver. messageReferences=0
看来我在某处遗漏了一些绑定,但我找不到它是什么。有人知道吗?
日志是这样说的:
AMQ221052: Deploying topic jms.topic.testEndpoint
它还说:
Couldn't find any bindings for address=testEndpoint
所以在我看来这只是 "jms.topic.testEndpoint" 和 "testEndpoint" 之间的简单不匹配。
看起来有两个问题:
- 在 MessageDriven 注释中,GlassFish 使用 mappedName,Wildfly 使用 ActivationConfigProperty(propertyName = "destination" ...。根据 post,我发现两者都很好。所以正确的格式是:
@MessageDriven(
mappedName = "testEndpoint", // GlassFish
activationConfig = {
@ActivationConfigProperty(propertyName = "destination",
propertyValue = "testEndpoint"), // Wildfly
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Topic")
})
- 在Wildfly配置中,主题名称应该与整个即对应:
<jms-topic name="testEndpoint"
entries="/jms/topic/testEndpoint"/>
我想在带有嵌入式 Apache Artemis 的 Wildfly 11 中接收 MQTT 消息。
当前状态:
我为 Wildfly 嵌入式 Apache Artemis 添加了 MQTT 协议支持(添加了 "missing" 文件夹和 artemis-mqtt-protocol-.jar 并在 module.xml)
我正在使用完整的独立配置并为 MTQQ 添加了接受器:
<subsystem xmlns="urn:jboss:domain:messaging-activemq:2.0"> <server name="default"> <remote-acceptor name="mqtt-acceptor" socket-binding="mqtt"> <param name="protocols" value="MQTT"/> </remote-acceptor>
主题为:
<jms-topic name="testEndpoint" entries="java:/jms/testEndpoint"/>
- 还添加了 mqtt 到套接字绑定
从日志中我可以看到它有效:
AMQ221020: Started Acceptor at 127.0.0.1:1883 for protocols [MQTT]
AMQ221007: Server is now live AMQ221001: Apache ActiveMQ Artemis Message Broker version 1.5.5.jbossorg-008
AMQ221003: Deploying queue jms.queue.DLQ
WFLYMSGAMQ0002: Bound messaging object to jndi name java:/ConnectionFactory
AMQ221003: Deploying queue jms.queue.ExpiryQueue
WFLYMSGAMQ0002: Bound messaging object to jndi name java:jboss/exported/jms/RemoteConnectionFactory
AMQ221052: Deploying topic jms.topic.testEndpoint
- 接下来我写了一个简单的MDB为:
@MessageDriven(
activationConfig = { @ActivationConfigProperty(propertyName = "destination",
propertyValue = "testEndpoint"),
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Topic")
},
mappedName = "testEndpoint")
public class TestEndpoint implements MessageListener {
private static final Logger logger = Logger.getLogger(TestEndpoint.class.getName());
public void onMessage(Message message) {
try {
logger.debug("message: " + message.getClass().getName());
} catch (Exception e) {
logger.debug("exception: " + e.getMessage());
}
}
}
- 我可以连接到端口 1883 上的服务器,当我向 testEndpoint 发送消息时,我可以在日志中看到:
SESSION CREATED: 63f14f85-0fa2-4fe7-a27b-03ef8e6639a2
Couldn't find any bindings for address=testEndpoint on message=ServerMessage[messageID=962,durable=true,userID=null,priority=0, bodySize=512, timestamp=0,expiration=0, durable=true, address=testEndpoint,properties=TypedProperties[mqtt.message.retain=true,mqtt.qos.level=1]]@749653273
Message ServerMessage[messageID=962,durable=true,userID=null,priority=0, bodySize=512, timestamp=0,expiration=0, durable=true, address=testEndpoint,properties=TypedProperties[mqtt.message.retain=true,mqtt.qos.level=1]]@749653273 is not going anywhere as it didn't have a binding on address:testEndpoint
QueueImpl[name=$sys.mqtt.retain.testEndpoint, postOffice=PostOfficeImpl [server=ActiveMQServerImpl::serverUUID=c58c74d5-ea71-11e7-9621-a434d929f4aa]]@6ff93fb4 doing deliver. messageReferences=0
看来我在某处遗漏了一些绑定,但我找不到它是什么。有人知道吗?
日志是这样说的:
AMQ221052: Deploying topic jms.topic.testEndpoint
它还说:
Couldn't find any bindings for address=testEndpoint
所以在我看来这只是 "jms.topic.testEndpoint" 和 "testEndpoint" 之间的简单不匹配。
看起来有两个问题:
- 在 MessageDriven 注释中,GlassFish 使用 mappedName,Wildfly 使用 ActivationConfigProperty(propertyName = "destination" ...。根据 post,我发现两者都很好。所以正确的格式是:
@MessageDriven(
mappedName = "testEndpoint", // GlassFish
activationConfig = {
@ActivationConfigProperty(propertyName = "destination",
propertyValue = "testEndpoint"), // Wildfly
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Topic")
})
- 在Wildfly配置中,主题名称应该与整个即对应:
<jms-topic name="testEndpoint" entries="/jms/topic/testEndpoint"/>