Message:

Subscribe rss
Blog categories
All | Backendless features
Feature 65: Basic publish/subscribe messaging
March 14, 2015 by markpiller
Spread the love

Publish/subscribe messaging has been around for a long time. The concept is rather simple – a program can publish a message to a queue or a topic, while another program subscribes to the queue or the topic to receive published messages. There are a lot caveats in the model with conditional delivery, message filtering, message transformations, etc. In this post I will demonstrate the most basic form of publish/subscribe messaging. One client will be publishing basic string messages, while any number of other client apps can subscribe to receive published messages. Consider the following example:

Asynchronous sample (Android and Plain Java):

Synchronous sample (Plain Java only):

Asynchronous sample:

Synchronous sample:

Asynchronous sample:

Synchronous sample:

Asynchronous sample:

Synchronous sample:

Both samples above publish string messages to the “default” channel. A channel is a logical medium carrying the messages. Think of it as a pipe connecting publisher with the subscribers. You can use your own messaging channels in your app – Backendless lets you create any number of channels.

 The code below is the subscriber. You can run that code in multiple instances of the program, for example, on different devices. Every running instance will be a separate subscriber:

The publisher code produces the following output:

While the subscriber prints out the following:

The code below is the subscriber.

 

The code below is the subscriber.

The code below is the subscriber.

Backendless Messaging is a very powerful piece of technology. I will be exploring many cool features included into it in the coming posts.

Share this post
Tweet about this on TwitterShare on FacebookGoogle+