"""
Demonstrates the client side of the synchronous request-response pattern
(also known as RPC or Remote Procedure Call) using proton.
"""
import optparse
from proton import Message, Url
from proton.utils import SyncRequestResponse, BlockingConnection
parser = optparse.OptionParser(usage="usage: %prog [options]",
description="Send requests to the supplied address and print responses.")
parser.add_option("-a", "--address", default="localhost:5672/examples",
help="address to which messages are sent (default %default)")
parser.add_option("-t", "--timeout", type="float", default=5,
help="Give up after this time out (default %default)")
opts, args = parser.parse_args()
url = Url(opts.address)
client = SyncRequestResponse(BlockingConnection(url, timeout=opts.timeout), url.path)
try:
REQUESTS = ["Twas brillig, and the slithy toves",
"Did gire and gymble in the wabe.",
"All mimsy were the borogroves,",
"And the mome raths outgrabe."]
for request in REQUESTS:
response = client.call(Message(body=request))
print("%s => %s" % (request, response.body))
finally:
client.connection.close()
Apache Qpid, Messaging built on AMQP; Copyright © 2015 The Apache Software Foundation; Licensed under the Apache License, Version 2.0; Apache Qpid, Qpid, Qpid Proton, Proton, Apache, the Apache feather logo, and the Apache Qpid project logo are trademarks of The Apache Software Foundation; All other marks mentioned may be trademarks or registered trademarks of their respective owners