2
votes

using Mule and MQTT I can't subscribe a client to multiple topics.

I configure config global element in this way:

<mqtt:config name="mqttSubscriber" doc:name="MQTT" brokerServerUri="${mqtt.url}" clientId="#['spy@'+server.host]" password="${mqtt.username}" username="${mqtt.password}">
   <mqtt:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_WAIT" maxActive="1" maxIdle="1" maxWait="1"/>
</mqtt:config>

In a flow I use:

<mqtt:subscribe config-ref="mqttSubscriber" doc:name="MQTTSubscriber1" topicFilter="a" qos="ONLY_ONCE"/>

and in another flow:

<mqtt:subscribe config-ref="mqttSubscriber" doc:name="MQTTSubscriber2" topicFilter="b" qos="ONLY_ONCE"/>

When the application starts, it is subscribed only to one topic.

What is wrong on my configuration? Maybe I have to create different clients?

Thanks at all in advance.

1

1 Answers

1
votes

Indeed, only one mqtt:subscribe is allowed per mqtt:config so you need to either:

  • Create a second mqtt:config and use it in the second mqtt:subscribe
  • Create a single multi-filter subscription and use a choice message processor to route messages based on the value of the mqtt.topicName inbound message property.

The latter would be better IMO since you'll only have a single active connection and it leverages MQTT's capacity to subscribe to multiple topics at once.