rabbitmq / rabbitmq/rabbitmq-java-client
Use ByteBuffers for message bodies
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.3k
- Forks
- 587
- Avg merge
- 7h 29m
- Merged PRs (30d)
- 41
Description
Hi all,
I would like to propose to use ByteBuffer for message bodies. Now, the API accepts a plain byte[], which forces intermediate copies of buffers if we are already working with ByteBuffer or similar representations of a buffer.
Internally, the client implementation can use array() and arrayOffset() to get the data to be sent over the wire if hasArray() returns true; or copy the contents with get() in the other case. In pure NIO mode, we could simply write the ByteBuffer to the java.nio.Channel without any intermediate overhead.
What do you think?
Thank you!
addendum
FWIW, although I believe native support for ByteBuffer is the preferred solution, we could also avoid the copy if the API would accept an offset in the provided array (+ optionally the length) as an alternative proposal:
channel.basicPublish(..., buffer.array(), buffer.arrayOffset());
channel.basicPublish(..., buffer.array(), buffer.arrayOffset(), <length>);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the channel.basicPublish(...) API and inspect how message-body byte[] values are converted and sent. Compare the proposed ByteBuffer and array-offset alternatives, including java.nio.Channel handling, then define the chosen API and verify that message bodies avoid unnecessary copies while preserving existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100