[rabbitmq-discuss] Posting MQTT to RabbitMQ QOS=1

Adrian Yip ayip at recondynamics.com
Fri Nov 22 02:19:29 GMT 2013


Hi,



I have a receiver that is waiting on an topic exchange and I can publish
MQTT messages with Mosquitto with QOS=0 just fine from multiple clients,
1000s of messages.



When I publish with QOS=1 however, the client appears successful in
publishing, but the receiver always stops at 20 messages.  I can kick off
another client without stopping the receiver and it will also do the same
thing, the receiver will show 20 messages and nothing more.



Ideas?



Adrian









Receive_json.py

------------------



#!/usr/bin/env python

import pika, traceback

import json



prev_id = 0



def callback(ch, method, properties, body):

    global prev_id



    ch.basic_ack(delivery_tag=method.delivery_tag)

    msgBody = json.loads(body)

    print " [x] %r:%r" % (method.routing_key,msgBody,)

    if prev_id + 1 != int(msgBody['id']):

        print "Missing %d" % (prev_id + 1)

    prev_id = msgBody['id']

    return





while True:

    try:



        connection = pika.BlockingConnection(pika.ConnectionParameters(

                host='localhost'))

        channel = connection.channel()



        channel.exchange_declare(exchange='mqtt.topic',

                                 type='topic')



        result = channel.queue_declare("mqtt-json-queue")

        queue_name = result.method.queue



        # topic here is what the mqtt plugin posts to

        channel.queue_bind(exchange='mqtt.topic',

                           queue=queue_name,

                           routing_key="json_routing_key")



        print ' [*] Waiting for logs. To exit press CTRL+C'



        channel.basic_consume(callback,

                              queue=queue_name

                              )



        channel.start_consuming()



    except Exception, e:

        traceback.print_exc()





Client

------



import mosquitto

import sys

import time

import random

import json



def on_connect(self, mosq, obj, rc):

    if rc == 0:

        print("Connected successfully.")



if len(sys.argv) != 4:

    print "Usage: cnt sleep_s qos"

    exit(-1)

cnt = int(sys.argv[1])

sleep_s = float(sys.argv[2])

qos = int(sys.argv[3])



client = mosquitto.Mosquitto("test-client%d" % random.randint(1,100))

print client._client_id



client.connect("localhost",port=1884)



i = 1

while i <=  cnt:

    print "Sending JSON msg %d via MQTT" % i

    msg = {}

    msg["id"] = i



    try :

        client.publish("json_routing_key",json.dumps(msg),qos=qos)

    except :

        print "Unexpected publish error: ",sys.exc_info()[0]

    i = i + 1



    time.sleep(sleep_s)



time.sleep(2)

try:

    client.disconnect()

except:

    print "Unexpected disconnect error: ",sys.exc_info()[0]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20131121/dc80cfb6/attachment.htm>


More information about the rabbitmq-discuss mailing list