Menu Search

server.py

import sys, optparse
from proton import *

parser = optparse.OptionParser(usage="usage: %prog <addr_1> ... <addr_n>",
                               description="simple message server")

opts, args = parser.parse_args()

if not args:
  args = ["amqp://~0.0.0.0"]

mng = Messenger()
mng.start()

for a in args:
  mng.subscribe(a)

def dispatch(request, response):
  if request.subject:
    response.subject = "Re: %s" % request.subject
  response.properties = request.properties
  print "Dispatched %s %s" % (request.subject, request.properties)

msg = Message()
reply = Message()

while True:
  if mng.incoming < 10:
    mng.recv(10)

  if mng.incoming > 0:
    mng.get(msg)
    if msg.reply_to:
      print msg.reply_to
      reply.address = msg.reply_to
      reply.correlation_id = msg.correlation_id
      reply.body = msg.body
    dispatch(msg, reply)
    mng.put(reply)
    mng.send()

mng.stop()

Download this file