Adding properties in ConsumerInterceptor doesn't work as expected
See original GitHub issueExpected behavior
I should be able to add and modify properties on a message in ConsumerInterceptor
and ProducerInterceptor
. Added or modified properties should be reflected when accessing them through the Message interface. Redelivery through reconsumeLater
and negativeAck
should have modified properties set. Additionally, I don’t think it should be necessary to cast to implementation classes to be able to modify the properties.
I’m basing my interceptor implementations on InterceptorsTest
Apologies if there is a better way to mutate a message but I couldn’t find any examples other than this test.
Actual behavior
ProducerInterceptor
works as expected and the property is set on the resulting message however, ConsumerInterceptor
the properties are only accessible if you cast to implementations and access the message builder and not in message properties. If you retry the message with reconsumeLater
then the properties on the retried message is not set.
My use case was to set a consumption count which is incremented in a interceptor or client code to allow us to implement an incremental back-off with reconsumeLater
.
Steps to reproduce
You can reproduce by modifying testConsumerInterceptorWithSingleTopicSubscribe
in InterceptorsTest
to use the Message
interface rather than iterating over the properties in the message builder.
MessageImpl<String> msg = (MessageImpl<String>) ((TopicMessageImpl<String>) received).getMessage();
for (KeyValue keyValue : msg.getMessageBuilder().getPropertiesList()) {
if ("beforeConsumer".equals(keyValue.getKey())) {
keyCount++;
}
}
System configuration
Pulsar version: 2.6.3 and 2.7.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
Yes, make sense. If you are interested in this enhancement, you can start a discussion in the dev email thread to share your ideas. Or you can create a separate issue to track the enhancement, this one this tracking the bug fix.
Closed as stale. Please create a new issue if it’s still relevant to the maintained versions.