rocketmq-client-python icon indicating copy to clipboard operation
rocketmq-client-python copied to clipboard

producer can't send byte string of an image file

Open zhxsxuan opened this issue 5 years ago • 3 comments

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'

zhxsxuan avatar Apr 20 '20 08:04 zhxsxuan

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.

ShannonDing avatar Apr 20 '20 08:04 ShannonDing

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.

zhxsxuan avatar Apr 22 '20 07:04 zhxsxuan

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.

samueljackson92 avatar May 27 '23 09:05 samueljackson92