Search code examples
javaspring-integrationactivemq-artemisspring-integration-mqtt

Mqttv5PahoMessageDrivenChannelAdapter is creating topic with client ID prefix


I am embedding ActiveMQ Artemis within Spring Boot application and I am trying to connect to MQTT port with Mqttv5PahoMessageDrivenChannelAdapter from Spring Integration:

@Bean
public ClientManager<IMqttAsyncClient, MqttConnectionOptions> clientManager(MqttConnectionOptions connectionOptions, MqttClientPersistence mqttClientPersistence) {
    Mqttv5ClientManager clientManager = new Mqttv5ClientManager(connectionOptions, "client-manager-client-id-v5");
    clientManager.setPersistence(mqttClientPersistence);
    return clientManager;
}

@Bean
public Mqttv5PahoMessageDrivenChannelAdapter agentRegistrationInputAdapter(
            ClientManager<IMqttAsyncClient, MqttConnectionOptions> clientManager,
            @Qualifier(AGENT_REGISTRATION_INPUT_CHANNEL) final MessageChannel channel) {
    final var adapter = new Mqttv5PahoMessageDrivenChannelAdapter(clientManager);
    adapter.setOutputChannel(channel);
    adapter.addTopic("agent.registration", 1);
    return adapter;
}

But what I see in the logs of the Artemis is the following:

o.a.a.a.core.server.impl.QueueImpl       : Scanning for expires on client-manager-client-id-v5.agent.registration
o.a.a.a.core.server.impl.QueueImpl       : Scanning for expires on client-manager-client-id-v5.agent.registration done

ActiveMQ Artemis creates the address agent.registration and under that address it creates queue client-manager-client-id-v5.agent.registration queue.

How can I avoid the client ID prefix for the queue?

UPDATE #1

If the queue already exists because it was created by definition during initialisation, then it is not created again by the Paho client with the prefix.

Its this behaviour expected? Are all client created queues always prefixed?


Solution

  • What you're seeing is the expected behavior.

    In ActiveMQ Artemis an MQTT topic is represented as an address and an MQTT subscription is represented as a queue. The queue is named according to the ID of the MQTT client that created it. This naming scheme separates MQTT subscriptions from different clients on the same topic. If you somehow avoid the prefix then it's likely that multiple MQTT clients would share the messages in the subscription which would violate the expected pub/sub semantics where every client gets every message.