Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pika
- import sys
- connection = pika.BlockingConnection(pika.ConnectionParameters(
- 'localhost', credentials=pika.PlainCredentials('guest','guest')))
- channel = connection.channel()
- channel.queue_declare(queue='request')
- channel.queue_bind(queue='request', exchange='amq.topic')
- def factorial(n):
- if n == 0:
- return 1
- else :
- return n * factorial (n -1)
- def on_request(ch, method, props, body):
- n = int(body)
- print (" [.] factorial(%s)") % (n,)
- response = factorial(n)
- #Publish message after processing response | Client is subscribed to this queue.
- ch.basic_publish(exchange='',
- routing_key='mqtt-subscription-client123qos1',
- properties=pika.BasicProperties(correlation_id = \
- props.correlation_id),
- body=str(response))
- ch.basic_ack(delivery_tag = method.delivery_tag)
- channel.basic_qos(prefetch_count=1)
- channel.basic_consume(on_request, queue='request')
- print (" Awaiting RPC requests")
- channel.start_consuming()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement