def callback(ch, method, properties, body): print(" [x] Received %r" % body) channel.basic_consume(callback, queue='hello', no_ack=True)
print("Receive the message", body)Receive the message b"Test Message"
bodyMessage = str(body, "utf-8") //the encoding is the message's encoding.
if bodyMessage =="xxxx":
//do some action--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
message = "quit"messageProps = pika.BasicProperties()messageProps.content_type="text/plain"messageProps.content_encoding="utf-8"messageProps.delivery_mode=2channel.basic_publish(exchange="", routing_key="xxxx", body=message, properties=messageProps)To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
As Luke explains, Pika doesn't do that.Message payloads are generally treated as opaque bags of bytes by client libraries,as encoding details is a runtime and application-specific concern.Generally we recommend using a data encoding library or widely used format (JSON, MsgPack,Protocol Buffers, Kryo, and so on) instead of strings for message payloads. Thoseformats will provide your payload both structure and interoperability (and in many cases,the degree of efficiency that custom application-specific parsers may or may not achieve).Of course, the tutorials try to explain as little as possible of those additional and system-specificdetails so we use text strings in payloads.
On Mon, Jun 19, 2017 at 4:37 PM, Luke Bakken <lba...@pivotal.io> wrote:
--Rick -This is a key difference between Python 2 and 3 and will affect much more in your Python application than just it's use of Pika.This has a great explanation: https://docs.python.org/3/howto/pyporting.html#text-versus-binary-dataWe may decide to use the value of content_encoding to decode the message payload for certain encoding values.Luke
On Sunday, June 18, 2017 at 8:52:00 PM UTC-7, Rick Hunter wrote:Dear Michael,I will read the tutorial code. But I still have one problem, why the byte stream can be recognized as string in Python 2, but cannot be recognized in Python 3?
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.