Programmer74 opened a new issue #2007: Implement an easier way to get the topic information from consumed message URL: https://github.com/apache/incubator-pulsar/issues/2007 ### Improvement request I create a consumer, which is subscribed to several topics using ```topicsPattern```: ``` Consumer consumer = client.newConsumer() .topicsPattern("persistent://public/default/test[12]") .subscriptionName("name") .subscribe(); ``` After receiving the message, I would like to know the actual topic name which the incoming message is from. In this case, I would like to check if the message was from "test1" or "test2". #### Expected behavior I would just do something like ``` Message msg = consumer.receive(); System.out.println(msg.getTopicName()); ```` #### Actual behavior But there is no such method. As I assumed from reading the sources, I have to do something like ``` Message msg = consumer.receive(); assert msg.getMessageId() instanceof TopicMessageIdImpl; TopicMessageIdImpl topicMessageId = (TopicMessageIdImpl)msg.getMessageId(); System.out.println(topicMessageId.getTopicName()); ``` which works, but is not intuitive. #### Request I suggest implementing an easier way of getting the topic information from the consuming message. It would be better if I could just call the ```msg.getTopicName()```, or ```msg.getMessageId().getTopicName()``` without nasty casting. Theoretically I could make PR myself with the adjustments I want, but I am not confident about the java library's internals. #### System configuration **Pulsar version**: ```v2.0.1-incubating```, ```v1.22.1-incubating```, possibly others
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
