【问题标题】:Receiving MQTT message with Wildlfy 11 embedded Apache Artemis使用 Wildlfy 11 嵌入式 Apache Artemis 接收 MQTT 消息
【发布时间】:2017-12-28 18:36:32
【问题描述】:

我想在 Wildfly 11 中使用嵌入式 Apache Artemis 接收 MQTT 消息。

当前状态:

  1. 我在 Wildfly 嵌入式 Apache Artemis 中添加了 MQTT 协议支持(添加了“缺失”文件夹和 artemis-mqtt-protocol-.jar 并在 module.xml 中启用了该协议)

    李>
  2. 我正在使用完整的独立配置并为 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"/>
  1. 还将 mqtt 添加到套接字绑定

从日志中我可以看到它有效:

AMQ221020:在 127.0.0.1:1883 开始接受协议 [MQTT]

AMQ221007:服务器现已上线 AMQ221001:Apache ActiveMQ Artemis Message Broker 版本 1.5.5.jbossorg-008

AMQ221003:部署队列 jms.queue.DLQ

WFLYMSGAMQ0002:将消息传递对象绑定到 jndi 名称 java:/ConnectionFactory

AMQ221003:部署队列 jms.queue.ExpiryQueue

WFLYMSGAMQ0002:将消息传递对象绑定到 jndi 名称 java:jboss/exported/jms/RemoteConnectionFactory

AMQ221052:部署主题 jms.topic.testEndpoint

  1. 接下来我写了一个简单的 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());
            }
        }

    }

  1. 我可以通过 1883 端口连接到服务器,当我向 testEndpoint 发送消息时,我可以在日志中看到:

已创建会话:63f14f85-0fa2-4fe7-a27b-03ef8e6639a2

找不到 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

消息 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 不会去任何地方,因为它没有绑定 地址:testEndpoint

QueueImpl[name=$sys.mqtt.retain.testEndpoint, postOffice=PostOfficeImpl [服务器=ActiveMQServerImpl::serverUUID=c58c74d5-ea71-11e7-9621-a434d929f4aa]]@6ff93fb4 做交付。 messageReferences=0

所以看起来我在某处缺少一些绑定,但我找不到它会是什么。有人知道吗?

【问题讨论】:

    标签: java jboss wildfly mqtt activemq-artemis


    【解决方案1】:

    日志是这样写的:

    AMQ221052:部署主题 jms.topic.testEndpoint

    它还说:

    找不到 address=testEndpoint 的任何绑定

    所以在我看来这是“jms.topic.testEndpoint”和“testEndpoint”之间的简单不匹配。

    【讨论】:

    【解决方案2】:

    看起来有两个问题:

    1. 在 MessageDriven 注释中,GlassFish 和 ActivationConfigProperty(propertyName = "destination" ... Wildfly 使用了 mappedName。根据帖子,我发现两者都很好。所以正确的格式如下:
    @MessageDriven( mappedName = "testEndpoint", // GlassFish activationConfig = { @ActivationConfigProperty(propertyName = "destination", propertyValue = "testEndpoint"), // Wildfly @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic") })
    1. 在 Wildfly 配置中,主题名称应与整个 ie 相对应:

    【讨论】:

      猜你喜欢
      • 2019-09-04
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-18
      相关资源
      最近更新 更多