problem with publish messages with paho

836 views
Skip to first unread message

Vasil Vasilev

unread,
Jun 17, 2016, 5:16:55 PM6/17/16
to rabbitmq-users
Hello team,
I am trying to use paho for publishing via mqtt protocol to Rabbitmq topic and the exchange has routing key to one queue.
everything is fine till the topic, but i dont see the messages.
can you tell me what i am missing.


here is the python script:

import paho.mqtt.client as paho
import time
 
mqtthost
= "localhost"  
mqttuser
= "user"  
mqttpass
= "pass"  
mqtttopic
= "amq.topic" - also tried "amq.topic/some routing key"  

def on_connect(client, userdata, flags, rc):
   
print("CONNACK received with code %d." % (rc))
def on_publish(client, userdata, mid):
   
print("mid: "+str(mid))
 
client
= paho.Client()
client
.on_connect = on_connect
client
.on_publish = on_publish
client
.username_pw_set(mqttuser,mqttpass)
client
.connect(mqtthost, 1883,60)


client
.loop_start()

while True:
    temperature
= "test data"
   
(rc, mid) = client.publish(mqtttopic, str(temperature), qos=1)
    time
.sleep(10)



exchange is amq.topic and i have added routing key for some local queue.
i see that there are Publish (IN) on this topic but queue is empty. If i publish manually via web one message, it goes to the queue. the question is from command line..

thanks.

Michael Klishin

unread,
Jun 18, 2016, 3:03:58 AM6/18/16
to rabbitm...@googlegroups.com
MQTT topic should be what you want the routing key to be. RabbitMQ MQTT plugin uses
a topic exchange under the hood and translates MQTT 3.1.1 topic wildcards into AMQP 0-9-1 ones.

Setting routing key to exchange name therefore makes no sense ;)

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ

Vasil Vasilev

unread,
Jun 18, 2016, 6:12:56 AM6/18/16
to rabbitmq-users
thank you for the answer.

now i got it :)
it is using the default amq.topic for mqtt publishing so i have to use only the key here in the config.
everything is working. thanks again.

Xhino Peci

unread,
Feb 9, 2017, 5:06:09 PM2/9/17
to rabbitmq-users
Hello Guys, I have the same problem as above, i can see message rates for PUBLISH, but there is nothing in the queue, please take a look at the code, if you can say that something is wrong ..
>>> import paho.mqtt.client as mqtt
>>> TOPIC = 'carje/kari/nepidh'
>>> BROKER = '127.0.0.1'
>>> client = mqtt.Client(
    client_id="KNPBRO",
    clean_session=False,
    protocol=mqtt.MQTTv311,
)
>>> client.will_set(TOPIC, 'NOW', qos=1, retain=False)
>>> client.connect(host=BROKER, port=1883)
>>> client.publish(TOPIC, str("NxirreTEqr"), retain=False)

Michael Klishin

unread,
Feb 9, 2017, 5:09:02 PM2/9/17
to rabbitm...@googlegroups.com
Your code doesn't include a single consumer, so the publishes may or may not be
routed anywhere.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages