+ Start a Discussion
kirkevonphillykirkevonphilly 

Streaming API - Multiple Subscriptions

Hi all,

I have two topics that I want to subscribe to in my JS, but am having difficulty in doing so.  Any suggestions?

 

Topics:

topic/topic1

topic/topic2

 

How would I add topic2 as an additional subscripiton?

 

$.cometd.subscribe('topic/topic1', function(message) {
    reRender_Tables();
});

 

MayTheForceBeWithYouMayTheForceBeWithYou

I have this same requirement. After taking a look into wildcard subscriptions, I believe this is possible. Unfortunately, I believe this may mean essentially subscribing to all pushtopics created in our orgs and then using an IF conditional to check that the message is coming from one of the topics we actually care about for the current page. I think some javascript that looks like the following should do the trick:

 

$.cometd.subscribe('/topic/*', function(message) {

    if (message.channel === '/topic/topic1' || message.channel === '/topic/topic2'){
        //Do Something
    }

}

  Full Disclaimer: I haven't implemented this to make sure it works, but given what I read I believe this should solve our problem. Happy coding!

MayTheForceBeWithYouMayTheForceBeWithYou

Bad news: no deposit, no return. Unfortunately this method didn't seem to pan out for me. I thought it would work because if you follow standard SF protocol by applying to only one topic and then doing a JS alert of the message.channel field you will indeed get the name displayed on the screen. Unfortunately I suppose for the time being Salesforce does not support wildcard subscriptions. That said, YMMV - let me know if you're able to sort this one out and sorry I wasn't of more help!