RabbitMQ - consume messages from a classic queue to a MQTT connection

49 Views Asked by At

I'm trying to consume messages from a queue in RabbitMQ which is already set up and has some messages. I am testing the MQTT subscriptor with a connection with the paho library:

import paho.mqtt.client as mqtt
from paho.mqtt.enums import CallbackAPIVersion

def on_connect(client, userdata, connect_flags, reason_code, properties):
    print("Connected with result code "+str(reason_code))
    client.subscribe("sv/iqf/area/0/#")

def on_message(client, userdata, msg):
    print("Received message: "+msg.payload.decode())

client = mqtt.Client(callback_api_version=CallbackAPIVersion.VERSION2)  # Provide callback_api_version argument
client.username_pw_set("user", "password")
client.on_connect = on_connect
client.on_message = on_message

client.connect("IP", 1883, 60)

client.loop_forever()

However, I can't make the new subscription queue (MQTT connection) consume the classic queue messages as described in the documentation:

Desired connection

My current set up for the classic queue to get the messages from is the following:

Queue with messages to consume from

And the MQTT subscription queue is set as:

Queue to send the messages to

If the connection is up and the messages are sent to the specified routing key then both queues will get the messages, but my goal is to get them to the first queue in case the subscriber connection is unstable and can consume them whenever it connects.

What am I missing?

1

There are 1 best solutions below

2
Gabriele Santomaggio On

I'm trying to consume messages from a queue in RabbitMQ which is already set up and has some messages.

It's not possible to consume via MQTT from a queue created outside the MQTT plugin.