qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brent Villalobos <Brent.Villalo...@pdi.dreamworks.com>
Subject Python: How to consume one message?
Date Tue, 04 Mar 2008 02:02:06 GMT
This is my first time using QPID and I'm trying to write a simple 
producer/consumer setup.  My producer is sending messages and the QPID 
broker is receiving and storing them just fine.  However, I want a 
consumer to process one message at a time.  My consumer code looks 
something like this:

host="localhost"
port=5672
amqp_spec="/usr/pic1/qpid-1.0-all/Python/specs/amqp.0-8.xml"
user="guest"
password="guest"

client = Client(host, port, qpid.spec.load(amqp_spec))
client.start({"LOGIN": user, "PASSWORD": password})
channel = client.channel(1)
channel.channel_open()
reply = channel.basic_consume(queue="message_queue", no_ack=True)
queue = client.queue(reply.consumer_tag)
msg = queue.get(timeout=1)
print "Consumer gets this message: ", msg.content.body
channel.channel_close()

I have a broker that has 10 messages on it.  When I run the consumer I 
get this:
Consumer gets this message:  I am a test message
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:

When I run the consumer again, this is the output:
Traceback (most recent call last):
  File "./consumer.py", line 31, in ?
    msg = queue.get(timeout=1)
  File "/usr/pic1/qpid-1.0-all/Python/python/qpid/queue.py", line 38, in get
    result = BaseQueue.get(self, block, timeout)
  File "/rel/lang/python/2.4.4-6/lib/python2.4/Queue.py", line 127, in get
    raise Empty
Queue.Empty

What am I doing wrong that all the messages in my queue are wiped out 
after I consume one message?
-Brent V.

Mime
View raw message