开发者

Avoiding data copying during a RabbitMQ BasicPublish

开发者 https://www.devze.com 2023-04-04 20:02 出处:网络
I have a requirement to use Rabbi开发者_开发知识库tMQ to send messages in a Java program.These messages contain 2 fields - A single byte identifier and many bytes of data.Since the method basicPublish

I have a requirement to use Rabbi开发者_开发知识库tMQ to send messages in a Java program. These messages contain 2 fields - A single byte identifier and many bytes of data. Since the method basicPublish takes a byte[] as the message body I am forced to copy these 2 parameters into a single array. And then on the receive side, I have to copy again to unwrap this. Is there any way to do this without the copies?


Since the single byte is an identifier, it can be considered as a meta information of the message: therefore I suggest you store it in a header of the message and not in the payload. The payload would then only contain your data.

0

精彩评论

暂无评论...
验证码 换一张
取 消