Filtering messages on a topic by the consumer

tbhargava18
tbhargava18 Member Posts: 9 ✭✭

I have a topic to which my backend service publishes the messages. I connect to that topic from my UI ( angular application) to consume the messages. I can have multiple browser sessions subscribing to the topic. I want to consume messages from the topic which are relevant to a browser session only

Answers

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 916 admin

    Hi @tbhargava18,

    How do you determine what is relevant to your browser session only? In Solace we recommend that you put things that need to be filtered on in the topic itself and the use our wildcard capabilities to subscribe to exactly the events you want.

    Here's a video showing how that works:

    Hope that helps!

  • tbhargava18
    tbhargava18 Member Posts: 9 ✭✭

    Hi Marc,

    Thanks for your response. I'll use the combination of logged in userId and another Id to determine what data I have to pick from the topic which would be relevant to the logged in user.

    The suggestion you provided above would require me to to create number of topics for each user, to publish user specific information which for me is not an ideal case. I want to publish to one topic and pick the relevant message

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 916 admin

    Hi @tbhargava18,

    Keep in mind that the topic is just metadata on the event which the broker can use for intelligent routing purposes. There is no need to "create number of topics for each user" as topics don't actually exist on the broker. So by using a topic hierarchy which includes the information you want to filter on in each topic this is what allows you to filter in a simple and performant way.

    Otherwise if you publish everything to one topic you then have to filter based on something else which isn't as performant. This could mean you still have the broker doing it by using user properties / selectors or your app has to receive all messages, look into the payload and throw away what they don't want.

    If it's a privacy concern maybe instead of userid you could use something like a browser session identifier? I'm not sure what's available that you could use?

  • tbhargava18
    tbhargava18 Member Posts: 9 ✭✭

    I can use a system generated id instead. Just trying to understand, if I use a topic hierarchy…there won't be N number of topics on the broker? Topic gets created and then what happens after we consume messages from the topic? Does it get removed after all messages are consumed ? I am sorry if I am sounding too naive but I am new to this messaging platform and trying to understand things better

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 916 admin

    Hi @tbhargava18,

    Correct → there won't be N topics created on the broker b/c the topic doesn't actually represent an object on the broker or file on the filesystem. A topic is just metadata on each message. No need to create or remove a topic. This is the magic that allows Solace to support essentially infinite topics.

    With that information in mind I'd suggestion re-watching Aaron's video I linked to earlier in this thread.

    *Note that if you need guaranteed delivery of messages, even if your app goes offline, you'd want to setup a guaranteed endpoint (usually a Queue) to facilitate that. That queue would then subscribe to your topics of interest. I get the feeling this will not be your cast with a browser based app, but I could be wrong :)

  • tbhargava18
    tbhargava18 Member Posts: 9 ✭✭

    Thanks Marc,

    That helped. I have one more doubt about the topics. What happens to the data published to topics that are not read by any subscriber. Do we have to do a deliberate cleanup of the topics or that is managed by Solace itself?

    I implemented topic hierarchy to publish and subscribe to messages. But there may be a situation where I publish messages to some topic but they may not be subscribed to, I am concerned about that..what happens to those topics?

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 916 admin

    Glad to help @tbhargava18

    That helped. I have one more doubt about the topics. What happens to the data published to topics that are not read by any subscriber. Do we have to do a deliberate cleanup of the topics or that is managed by Solace itself?

    Nope, no clean-up necessary! if there are no subscribers then the broker won't keep it around unless you have replay configured for that topic.