Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PIP 96] Add message payload processor for Pulsar client #12088

Merged

Conversation

BewareMyPower
Copy link
Contributor

@BewareMyPower BewareMyPower commented Sep 18, 2021

Master Issue: #12087

Motivation

See #12087 for details.

Modifications

  • Add MessagePayloadContext, MessagePayload, MessagePayloadProcessor interfaces following the PIP 96.
  • Add MessagePayloadImpl, which uses ByteBuf as the backed buffer, as the default implementation of MessagePayload.
  • Add MessagePayloadFactory, the DEFAULT field is an instance that can wrap a byte array or NIO buffer to a MessagePayloadImpl object.
  • Add MessagePayloadUtils class to convert MessagePayload to ByteBuf. No bytes copy happens if the MessagePayload is MessagePayloadImpl.
  • Refactor ConsumerImpl to provide methods to create a single message in batch or a normal message based on metadata and payload. Some repeated code is also removed.
  • Add MessagePayloadContextImpl as the default implementation of MessagePayloadContext. It uses methods from ConsumerImpl to create a Message based on a MessagePayload.
  • Support configuring MessagePayloadProcessor in ConsumerBuilder.
  • Add consumeMessagesFromConverter method to ConsumerImpl when a payload converter is configured.

Verifying this change

  • Make sure that the change passes the CI checks.

  • Add MessagePayloadTest to test converting MessagePayload to ByteBuf, it covers the cases for both the default MessagePayloadImpl and another implementation based on a NIO ByteBuffer.

  • Add MessagePayloadProcessorTest, which includes two tests:

    • testDefaultProcessor: Test the default processor could work. In addition, it checks the refCnt to verify after MessagePayloadContext creates a Message<T>, the ByteBuf will be released.
    • testCustomProcessor: Test the processor for custom message format that represents a batched message.
      • CustomBatchFormat: Define the custom message format.
      • CustomBatchProducer: A producer that writes the custom formatted message to bookie directly. When the batch is full, send the batch.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (yes)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (no)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (no)

@BewareMyPower BewareMyPower added area/client doc-required Your PR changes impact docs and you will update later. type/PIP labels Sep 18, 2021
@BewareMyPower BewareMyPower added this to the 2.9.0 milestone Sep 18, 2021
@BewareMyPower BewareMyPower self-assigned this Sep 18, 2021
@BewareMyPower BewareMyPower changed the title [PIP 96] Add payload converter for Pulsar client [PIP 96] Add message payload processor for Pulsar client Sep 30, 2021
@BewareMyPower
Copy link
Contributor Author

Now this PR is ready for review. And the PR description was updated as well.

Currently there's two +1 in vote email, you can take a look first, @eolivelli @codelipenghui

@BewareMyPower
Copy link
Contributor Author

@eolivelli @315157973 @codelipenghui @hangc0276 @merlimat @rdhabalia PTAL when you have time since Pulsar 2.9.0 release cut is coming.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work

I left some minor comments PTAL

@BewareMyPower
Copy link
Contributor Author

Comments were addressed, PTAL again @eolivelli

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@eolivelli eolivelli modified the milestones: 2.9.0, 2.10.0 Oct 6, 2021
@eolivelli eolivelli merged commit 86b2a21 into apache:master Oct 6, 2021
@BewareMyPower BewareMyPower deleted the bewaremypower/message-converter branch October 6, 2021 08:46
@Anonymitaet Anonymitaet added doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. and removed doc-required Your PR changes impact docs and you will update later. labels Oct 15, 2021
@Anonymitaet
Copy link
Member

Confirmed with @BewareMyPower, this PR adds docs in JavaDoc

bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/client doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. release/2.9.0 type/PIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants