在 RabbitMQ BasicPublish 期间避免数据复制
我需要在Java程序中使用RabbitMQ发送消息。这些消息包含 2 个字段 - 一个单字节标识符和许多字节数据。由于 basicPublish 方法采用 byte[] 作为消息正文,因此我被迫将这两个参数复制到单个数组中。然后在接收端,我必须再次复制才能打开它。有没有办法在没有副本的情况下做到这一点?
I have a requirement to use RabbitMQ 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于单字节是一个标识符,因此可以将其视为消息的元信息:因此我建议您将其存储在 消息头,而不是有效负载。然后有效负载将只包含您的数据。
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.