<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>RE: losing messages</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P DIR=LTR><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT COLOR="#1F497D" FACE="Calibri">Perhaps there is something wrong with my consumer</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT COLOR="#1F497D" FACE="Calibri">…</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT COLOR="#1F497D" FACE="Calibri">Here is the python code :</FONT></SPAN></P>
<BR>
<P DIR=LTR><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="fr-ca"><FONT FACE="Courier New"># MG </FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="fr-ca"><FONT FACE="Courier New">import amqplib.client_0_8 as amqp</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"><FONT FACE="Courier New">import os,sys,time</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">machine = sys.argv[1]</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">user = "anonymous"</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">passwd = "anonymous"</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">exchange_realm = "/data"</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">exchange_name = "cmc"</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">exchange_type = "topic"</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"># being notified for all URLs</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">exchange_key = "exp.dd.notify.#"</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">#exchange_key = "exp.dd.notify.radar.PRECIP.GIF.WBI"</FONT></SPAN></P>
<BR>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"># being notified for a reception in <A HREF="http://weather.gc.ca/radar/CAPPI/GIF/XAM">http://weather.gc.ca/radar/CAPPI/GIF/XAM</A></FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">#exchange_key = "exp.dd.notify.radar.CAPPI.GIF.XAM"</FONT></SPAN></P>
<BR>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"># connection</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">connection = amqp.Connection( machine,userid=user,password=passwd,ssl=False)</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">channel = connection.channel()</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"># exchange</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">channel.access_request(exchange_realm, active=True, read=True)</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">channel.exchange_declare(exchange_name, exchange_type, auto_delete=True)</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"># queue</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">_queuename, message_count, consumer_count = channel.queue_declare()</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">channel.queue_bind(_queuename, exchange_name, exchange_key)</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"># amqp callback</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">def amqp_callback(msg):</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> hdr = msg.properties['application_headers']</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> filename = hdr['filename']</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> msg.channel.basic_ack(msg.delivery_tag)</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> # Cancel this callback</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> if msg.body == 'quit':</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> msg.channel.basic_cancel(msg.consumer_tag)</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> self.msg = None</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> self.logger.error('CRITICAL ERROR...')</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> self.logger.error('Requiered to quit the connection')</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> sys.exit(1)</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> # send url to user callback</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> user_callback(msg.body)</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">###################################</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"># user callback</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">###################################</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">def user_callback(url):</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> t = time.strftime("%Y%m%d %H:%M:%S",time.gmtime())</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> print("%s %s" % (t,url))</FONT></SPAN></P>
<BR>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"># amqp callback activation</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">channel.basic_consume(_queuename, callback=amqp_callback)</FONT></SPAN></P>
<BR>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"># Wait for things to arrive on the queue</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">while True:</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> try:</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> channel.wait()</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> except:</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> channel.close()</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> connection.close()</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"> sys.exit(1)</FONT></SPAN></P>
<BR>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New"># close connections</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">channel.close()</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"><FONT FACE="Courier New">connection.close()</FONT></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-ca"></SPAN></P>
<UL DIR=LTR><UL DIR=LTR>
<P DIR=LTR><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-ca"></SPAN></P>
</UL></UL>
<P DIR=LTR><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-ca"></SPAN></P>
<P DIR=LTR><SPAN LANG="en-us"></SPAN></P>
</BODY>
</HTML>