apache / rocketmq-client-python

Apache RocketMQ python client
https://rocketmq.apache.org/
Apache License 2.0
272 stars 95 forks source link

producer can't send byte string of an image file #87

Open zhxsxuan opened 4 years ago

zhxsxuan commented 4 years ago

I tried to send sync a byte string read from an image to RMQ by the following code:

with open("model/test.jpeg", "rb") as f:
    img_str = f.read()
msg.set_body(img_str)
ret = producer.send_sync(msg)

but the message body a consumer received is only a part of the byte string

b'\xff\xd8\xff\xdb'
ShannonDing commented 4 years ago

the py SDK does not support the binary message body. maybe you can encode the byte body using base64 encoding before sending and decode it before consuming. another way, you can try to add a new API to set a binary message body using a special C API "SetByteMessageBody" instead.

zhxsxuan commented 4 years ago

the py SDK does not support the binary message body. maybe you can encode the byte body using base64 encoding before sending and decode it before consuming. another way, you can try to add a new API to set a binary message body using a special C API "SetByteMessageBody" instead.

I tried changing the set_body function as following

    def set_body(self, body):
        if isinstance(body, binary_type):
            ffi_check(dll.SetByteMessageBody(self._handle, _to_bytes(body), len(body)))
        ffi_check(dll.SetMessageBody(self._handle, _to_bytes(body)))

But the message received was not changed.

samueljackson92 commented 1 year ago

Hi @ShannonDing, is there any further update on this issue? I tired a similar hack to @zhxsxuan above using SetByteMessageBody, and also did not receive any sensible message.