james-bright-helix opened a new issue #9803:
URL: https://github.com/apache/pulsar/issues/9803


   #### 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](https://github.com/apache/pulsar/blob/master/pulsar-broker/src/test/java/org/apache/pulsar/client/api/InterceptorsTest.java)
   
   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](https://github.com/apache/pulsar/blob/master/pulsar-broker/src/test/java/org/apache/pulsar/client/api/InterceptorsTest.java)
   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
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to