[rabbitmq-discuss] losing messages

Grenier,Michel [CMC] Michel.Grenier at ssc-spc.gc.ca
Thu Sep 5 20:04:35 BST 2013


Perhaps there is something wrong with my consumer...
Here is the python code :


# MG 

import amqplib.client_0_8 as amqp
import os,sys,time

machine        = sys.argv[1]
user           = "anonymous"
passwd         = "anonymous"

exchange_realm = "/data"
exchange_name  = "cmc"
exchange_type  = "topic"

# being notified for all URLs
exchange_key   = "exp.dd.notify.#"
#exchange_key   = "exp.dd.notify.radar.PRECIP.GIF.WBI"


# being notified for a reception in
http://weather.gc.ca/radar/CAPPI/GIF/XAM

#exchange_key   = "exp.dd.notify.radar.CAPPI.GIF.XAM"


# connection
connection = amqp.Connection(
machine,userid=user,password=passwd,ssl=False)
channel    = connection.channel()

# exchange
channel.access_request(exchange_realm, active=True, read=True)
channel.exchange_declare(exchange_name, exchange_type, auto_delete=True)

# queue
_queuename, message_count, consumer_count = channel.queue_declare()
channel.queue_bind(_queuename, exchange_name, exchange_key)

# amqp callback

def amqp_callback(msg):

    hdr = msg.properties['application_headers']
    filename = hdr['filename']

    msg.channel.basic_ack(msg.delivery_tag)

    # Cancel this callback
    if msg.body == 'quit':
       msg.channel.basic_cancel(msg.consumer_tag)

       self.msg = None
       self.logger.error('CRITICAL ERROR...')
       self.logger.error('Requiered to quit the connection')
       sys.exit(1)

    # send url to user callback
    user_callback(msg.body)

###################################
# user callback
###################################

def user_callback(url):
    t = time.strftime("%Y%m%d %H:%M:%S",time.gmtime())
    print("%s %s" % (t,url))


# amqp callback activation

channel.basic_consume(_queuename, callback=amqp_callback)


# Wait for things to arrive on the queue

while True:
     try:
        channel.wait()
     except:
        channel.close()
        connection.close()
        sys.exit(1)


# close connections

channel.close()
connection.close()




		


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130905/09910415/attachment.htm>


More information about the rabbitmq-discuss mailing list