2

I have created a MQTT topic from Python client on the RabbitMQ broker installed in localhost . I am publishing few messages in this topic and able to see those in MQTTLens Chrome plug-in also from the Subscriber written in Python. Where to see the list of topics created in RabbitMQ broker? I have enabled web interface for this server . But I am not able to see the topic under "Exchanges" tab . Please let me know where to see the topics and individual messages on each topic.

Publisher:

import paho.mqtt.client as paho

broker = "localhost"
port = 1883


def on_publish(client, userdata, result):  # create function for callback
    print("message published \n",userdata,result)
    pass


client1 = paho.Client("client1")  # create client object
client1.on_publish = on_publish  # assign function to callback
client1.connect(broker, port)  # establish connection
ret = client1.publish("home", "test-message")  # publish

Subscriber :

import paho.mqtt.client as paho

broker = "localhost"
port = 1883


def on_subscribe(client, userdata, ret, granted_qos):  # create function for callback
    print("started subscribing ... \n",userdata,ret)
    pass


def on_message(client, userdata, message):
    print("Received message '" + str(message.payload) + "' on topic '"
          + message.topic + "' with QoS " + str(message.qos))


client2 = paho.Client("client2")  # create client object
client2.on_subscribe = on_subscribe
client2.connect(broker, port)  # establish connection
ret = client2.subscribe(("home", 1))
client2.on_message = on_message
client2.loop_forever()
4

0 回答 0