mqttactivemq-artemis

ActiveMQ Artemis: prefer available consumers in MQTT shared subscriptions


I have an ActiveMQ Artemis broker with two MQTT consumers subscribed to topic $share/tasks, with all parts configured to use QoS 2. Messages are distributed among the consumers following the round-robin algorithm, without regards for consumer availability. As such, the following problematic situation can happen:

I was hoping manual acknowledgment would be the answer here, only acknowledging the slow task after completion, but messages keep being assigned to consumer #1 even if it has not acknowledged prior ones.


Solution

  • The messages keep being assigned to consumer #1 even if it has not acknowledged prior ones might have the following reasons:

    1. You are using QoS 0 and manual acknowledgment only works with QoS 1 and 2. (based on the https://hivemq.github.io/hivemq-mqtt-client/docs/advanced-usage/ reference you provided)
    2. You have "receiveMaximum" > 1 (receiveMaximum is the maximum number of unacknowledged PUBLISH messages the client can accommodate).

    By using QoS 1 or 2 and receiveMaximum=1 you can ensure a consumer does not receive another message until it finishes the current one.