I am trying to make a simple AMQP client using python. I copied the code I found in RabbitMQ website:
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
channel.basic_consume(callback,
queue='hello',
no_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
This works except It always prints something like [x] Received b'my message'. Due to this I cant parse my json messages. How do I fix this ?
You may use decode() to convert the string to utf-8 and then print it out, something like
str = 'your str'
print(str.decode())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With