Message:

Subscribe rss
Blog categories
All | Backendless features
Feature 73: Conditional message delivery with subtopics
March 22, 2015 by markpiller
Spread the love

In my previous post I described a feature for conditional pub/sub message delivery using SQL selectors. With that (selector) approach the publisher must attach headers to the message and the subscriber uses an SQL-based condition which references header names and values. In addition to selectors, Backendless supports another type of conditional delivery – subtopics. Consider the following example:

A message with an announcement from Microsoft is published to topic stocks.nasdaq.msft. Another message from IBM is published to stocks.nyse.ibm. Suppose a subscribe wants to receive all messages related to stock announcements. In this case, it subscribes to the stocks.* subtopic. Another subscriber is interested in all Nasdaq announcements. That subscriber subscribers to the stocks.nasdaq.* subtopic. Finally, to receive Microsoft announcements, a subscriber would use the stocks.nasdaq.msft subtopic. As you can see Backendless uses the federated subtopic structure for message filtering/delivery. The sample below shows how to use subtopics in the Backendless messaging API:

Asynchronous API sample (Android and Plain Java):

Synchronous API sample (Plain Java only):

The code above publishes two messages to the  news.dallas.sports and news.us.technology topics. Also notice, the published message is a custom strongly-typed object (as opposed to a primitive data type or a string). The code below subscribes to receive message published to the news.* subtopic. When you run that code, it will receive both messages from the publisher. However, if you modify the subscriber to receive messages from the news.us.* subtopic, it will receive only one of them (repeatedly though as the messages are published in a loop):

Enjoy!

 

Share this post
Tweet about this on TwitterShare on FacebookGoogle+