Receiving MQTT message with Wildlfy 11 embedded Ap

2019-08-06 01:45发布

问题:

I would like to receive MQTT messages in Wildfly 11 with the embedded Apache Artemis.

Current state:

  1. I added the MQTT protocol support to the Wildfly embedded Apache Artemis (added the "missing" folder and artemis-mqtt-protocol-.jar and enabled the protocol in the module.xml)

  2. I am using the full standalone configuration and added acceptor for 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>

and topic as:

<jms-topic name="testEndpoint" entries="java:/jms/testEndpoint"/>
  1. Also added the mqtt to socket binding

From the log I can see that it works:

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

  1. Next I wrote a simple MDB as:


    @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. I can connect to the server on port 1883 and when I send a message to testEndpoint I can see in the logs:

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

So it looks like I am missing some binding somewhere, but I can not find what it would be. Anybody has any idea?

回答1:

The log says this:

AMQ221052: Deploying topic jms.topic.testEndpoint

And it also says this:

Couldn't find any bindings for address=testEndpoint

So it looks to me like it's a simple mismatch between "jms.topic.testEndpoint" and "testEndpoint".



回答2:

It looks like there were two problems:

  1. In the MessageDriven annotation the mappedName is used by GlassFish and ActivationConfigProperty(propertyName = "destination" ... by Wildfly. According to post I found both is fine. So the correct format is as:


    @MessageDriven(                
        mappedName = "testEndpoint", // GlassFish    
        activationConfig = { 
            @ActivationConfigProperty(propertyName = "destination", 
                                      propertyValue = "testEndpoint"),  // Wildfly
            @ActivationConfigProperty(propertyName = "destinationType",                                                      
                                      propertyValue = "javax.jms.Topic")
    })


  1. In the Wildfly configuration one should have the name of the topic correspond to the entire ie:

<jms-topic name="testEndpoint" entries="/jms/topic/testEndpoint"/>