apache / apache/pulsar

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

Open
#23,800 0 comments 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.

### Read release policy

- [X] 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.

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

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

@Override
public void onSendAcknowledgement(Producer producer, Message message, MessageId msgId,
Throwable exception) {
messageValueOnSendAcknowledgement.add(message.getValue());
}
};
@Cleanup
Producer 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!

Contributor guide

Open the contributing guide

Research direction

Start with the provided testProducerInterceptorAccessMessageValue test and the ProducerInterceptor#onSendAcknowledgement callback, reproducing the behavior on a supported 2.11+ client and broker. Trace the Message passed to the callback; done when message.getValue() returns "Hello, Pulsar!" and both assertions pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
distributed-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.