Skip to content

Implement an easier way to get the topic information from consumed message #2007

Closed

Description

@nikita-tomilov

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 at all.

System configuration

Pulsar version: v2.0.1-incubating, v1.22.1-incubating, possibly others

Activity

  1. added
    type/enhancement
    on Jun 21, 2018
  2. self-assigned this
    on Jul 11, 2018
  3. sijie commented on Sep 19, 2018

    @sijie
    Member

    This has been implemented and merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/clienttype/enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions