Avoiding data copying during a RabbitMQ 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.
精彩评论