I've attached one way to do a multi-threaded request/reply server. There
are others as well. Is this the sort of thing you're looking for?
Note that this uses the latest version of the API from trunk which does
have a few naming changes relative to the 0.6 version, however this
should work on the 0.6 version as will with some minor tweaks.
--Rafael
Cajus Pollmeier wrote:
I'm facing a similar problem. Maybe it would be a good thing to move an example
to the wiki to allow others a more rapid coding start.
My 5 cent,
Cajus
Am 08.04.2010 um 15:26 schrieb Carl Trieloff:
This can be done with the qpid python libs, there are a few threads on the list
already on the topic.
If you can't locate them in the archive, shout, and we can maybe post an
example and post it on the
wiki.
Carl.
On 04/07/2010 05:04 AM, Kiss Péter wrote:
Hi everyone,
I'm quite new to Qpid and AMQP, and trying to figure out,
how to write a robust multithreaded request/reply server and
a client in python. (The long term goal is to publish an API
with apache avro RCP using AMQP as a transport.)
I'm using the v0.6 Qpid Java broker and the enclosed python library.
The python API documentation is very poor, the examples are quite heplful,
but too simple. Browsing the code, I found the peer.py and client.py, but
couldn't find an example how to use them in a real application.
Any help or code snippet would be much appreciated.
Or, if I'm digging in the wrong direction, please point me to the right way.
I'm aware of the fact, that there are more AMQP libraries for python,
(txamqp, amqplib), but none of them seems to be as up to date as qpid.
(Actually txamqp seems great, but using twisted is a bit frightening.)
Thanks
kodiak
<a href="" target="_blank"><br><br>________________________________________________________<br><a
href="http://ad.adverticum.net/b/cl,1,73468,1595374,1595372/click.prm">Nálunk a nyelvtanfolyamok garantáltan elindulnak! Jelentkezz 20%
kedvezménnyel a 20 éves Katedra Budapesthez április 7-9. között!</a></a>
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]
import traceback
from qpid.messaging import *
from threading import Thread
class Processor(Thread):
def __init__(self, ssn):
Thread.__init__(self)
self.setDaemon(True)
self.ssn = ssn
def run(self):
while True:
msg = self.ssn.next_receiver().fetch()
try:
to, reply = self.process(msg)
snd = ssn.sender(to)
snd.send(reply)
snd.close()
self.ssn.acknowledge(msg)
except:
traceback.print_exc()
print "rejecting: %s" % msg
self.ssn.acknowledge(msg, Disposition(REJECTED))
def process(self, msg):
return msg.reply_to, Message("echo %s" % msg.content)
conn = Connection.establish("localhost")
processors = []
for i in range(10):
ssn = conn.session()
rcv = ssn.receiver("requests", capacity=10)
proc = Processor(ssn)
proc.start()
processors.append(proc)
# this may look a bit weird, but the timed join keeps python from
# swallowing interrupts
while True:
for p in processors:
p.join(3)
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]