question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding properties in ConsumerInterceptor doesn't work as expected

See original GitHub issue

Expected 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:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
codelipenghuicommented, Mar 4, 2021

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.

0reactions
tisonkuncommented, Dec 11, 2022

Closed as stale. Please create a new issue if it’s still relevant to the maintained versions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kafka ConsumerInterceptor onCommit not being called when ...
I'm attempting to use a Kafka ConsumerInterceptor to intercept when offsets are committed. This seems to work producers transactions are not ...
Read more >
Document how to wire other beans in Spring Kafka producer ...
Hi , Please let me know how to auto wire beans with spring Kafka producer/consumer interceptor. Interceptor works fine and getting invoked ...
Read more >
spring-projects/spring-kafka - Gitter
after you mentioning, I added explicit @TestPropertySource(locations = "classpath:/file-test.properties") and now it is resolving.
Read more >
Properties · The Internals of Apache Kafka
In IaaS environments (e.g. Docker, Kubernetes, a cloud), advertised.listeners may need to be different from the interface to which a Kafka broker binds....
Read more >
Spring for Apache Kafka
Prerequisites: You must install and run Apache Kafka. ... Here is an example of an application that does not use Spring Boot; it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found