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

[Bug] Cannot access message value via Message#getValue inside ProducerInterceptor#onSendAcknowledgement #23800

Open
2 of 3 tasks
Shawyeok opened this issue Jan 2, 2025 · 0 comments
Labels
type/bug The PR fixed a bug or issue reported a bug

Comments

@Shawyeok
Copy link
Contributor

Shawyeok commented Jan 2, 2025

Search before asking

  • I searched in the issues and found nothing similar.

Read release policy

  • I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.

Version

2.11+

Minimal reproduce step

When I was working on #23791, I added another unit test to verify accessing the message value via Message#getValue inside onSendAcknowledgement. However, it returned an empty string, causing the test to fail at the final assertion.

    @Test
    public void testProducerInterceptorAccessMessageValue() throws PulsarClientException {
        List<String> messageValueOnSendAcknowledgement = Collections.synchronizedList(new ArrayList<>());
        ProducerInterceptor<String> interceptor = new ProducerInterceptor<>() {
            @Override
            public void close() {
            }

            @Override
            public Message<String> beforeSend(Producer<String> producer, Message<String> message) {
                return message;
            }

            @Override
            public void onSendAcknowledgement(Producer<String> producer, Message<String> message, MessageId msgId,
                                              Throwable exception) {
                messageValueOnSendAcknowledgement.add(message.getValue());
            }
        };
        @Cleanup
        Producer<String> producer = pulsarClient.newProducer(Schema.STRING)
                .topic("persistent://my-property/my-ns/my-topic")
                .intercept(interceptor)
                .create();

        try {
            producer.newMessage().value("Hello, Pulsar!").send();
        } catch (Exception ignore) {
        }
        Assert.assertEquals(messageValueOnSendAcknowledgement.size(), 1);
        Assert.assertEquals(messageValueOnSendAcknowledgement.get(0), "Hello, Pulsar!");
    }

The same test works on pulsar client versions prior to 2.11.0, this issue possibly relate to #16605 (not sure yet.)

What did you expect to see?

Return message value properly

What did you see instead?

Empty message returned

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!
@Shawyeok Shawyeok added the type/bug The PR fixed a bug or issue reported a bug label Jan 2, 2025
@Shawyeok Shawyeok closed this as completed Jan 3, 2025
@Shawyeok Shawyeok reopened this Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

No branches or pull requests

1 participant