Skip to content

Use ByteBuffers for message bodies #421

Open
@pbillen

Description

@pbillen

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>);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions