在 RabbitMQ BasicPublish 期间避免数据复制

发布于 2024-12-04 04:35:56 字数 159 浏览 3 评论 0原文

我需要在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流年里的时光 2024-12-11 04:35:56

由于单字节是一个标识符,因此可以将其视为消息的元信息:因此我建议您将其存储在 消息头,而不是有效负载。然后有效负载将只包含您的数据。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文