[rabbitmq-discuss] py-amqplib status messages

Matthias Radestock matthias at lshift.net
Fri Nov 21 08:18:08 GMT 2008


Tsuraan,

tsuraan wrote:
> Code samples:
> message inserter, which is run first:
> 
> def main():
>   conn = A.Connection('localhost', userid='tsuraan', password='tsuraan')
>   chan = conn.channel()
> 
>   for i in range(1000):
>     m = A.Message(str(i), delivery_mode=2)
>     chan.basic_publish(m, 'rawmsg', 'standard', mandatory=True, immediate=False)
> 
> if __name__ == "__main__":
>   main()

The above program exits without closing the channel or connection 
properly first. As a result, any messages that are "in flight" will be lost.

> def main():
>   conn = A.Connection('localhost', userid='tsuraan', password='tsuraan')
>   chan = conn.channel()
> 
>   nums = []
>   while True:
>     chan.tx_select()
>     msg = chan.basic_get("msgq", no_ack=True)
>     if msg is None:
>       print 'all done'
>       break
>     else:
>       print 'got message', msg.body
>       nums.append(msg.body)
> 
>     dtag = msg.delivery_info['delivery_tag']
>     chan.basic_ack(dtag)
>     chan.tx_commit()
> 
>   print len(nums)
> 
> if __name__ == "__main__":
>   main()

Why are you using tx in the above? It won't do any harm, but it doesn't 
seem to serve any purpose.

As above, you should close the channel and connection properly before 
exiting.

> When the first program is run, it runs for a moment, and then exits
> without any errors.  The second program is run, and it only gets a few
> hundred messages.  The ids that it gets are always sequential numbers,
> starting with 0.  It's as though the last couple of hundred messages
> just never happened, although they were published.

That is most likely due to the lack of proper channel/connection closure 
in the producer code.


Matthias.




More information about the rabbitmq-discuss mailing list