Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AMQP Python3 pika 1.0.0 publish/consume examples
#!/usr/bin/env python
import pika
# At the moment (2019-04-07) the official examples provided by CloudAMQP are not working anymore
# because pika 1.0.0 has changed
# moreover, the official examples are in Python 2
# these examples have a few benefits:
# they work with python3
# they work with pika 1.0.0
# they were tested with amqps
# feel free to use them
url = 'your_amqps_string'
params = pika.URLParameters(url)
params.socket_timeout = 5
connection = pika.BlockingConnection(params)
channel = connection.channel()
channel.basic_publish(exchange='', routing_key='hello', body='Hello V3')
connection.close()
#!/usr/bin/env python
import pika
# At the moment (2019-04-07) the official examples provided by CloudAMQP are not working anymore
# because pika 1.0.0 has changed
# moreover, the official examples are in Python 2
# these examples have a few benefits:
# they work with python3
# they work with pika 1.0.0
# they were tested with amqps
# feel free to use them :)
url = 'your_amqps_string'
params = pika.URLParameters(url)
connection = pika.BlockingConnection(params)
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch, method, properties, body):
print(" [x] Received " + str(body))
channel.basic_consume('hello', callback, auto_ack=True)
channel.start_consuming()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.