Cluster Topic Publisher and Subscriber Adapters Sample

This topic describes how to run the Cluster Publisher and Subscriber adapters sample application, which illustrates how to use the adapters to send tuples to a cluster-wide topic and receive these tuples by subscribing to the same topic. For further information on this adapter, see Cluster Topic Publisher and Subscriber Adapters.

Sample Overview

This sample includes one Publisher adapter and one Subscriber adapter, both using the same topic (named SampleTopic) so that tuples sent to the Publisher will be received by the Subscriber. Note that while both adapters live in the same fragment to simplify the sample's deployment, they could also be in separate applications running on separate nodes of a given cluster and still work in the same manner, with no additional configuration. Moreover, multiple instances of both Publisher and Subscriber adapters may use the same topic on a cluster.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, select File>Import Samples and Community Content.

  • Enter cluster to narrow the list of options.

  • Select Publish and subscribe across fragments and nodes of a cluster from the Extending StreamBase category.

  • Click Import Now.

StreamBase Studio creates a project for the sample.

Running This Sample in StreamBase Studio

The steps to run this sample in Studio are as follows:

  1. In the Project Explorer view, open the sample you just loaded.

    If you see red marks on a project folder, wait a moment for the project to load its features.

    If the red marks do not resolve themselves after a minute, select the project, right-click, and select Maven>Update Project from the context menu.

  2. Open the src/main/eventflow/packageName folder.

  3. Open the clusterpubsub.sbapp file and click the Run button. This opens the SB Test/Debug perspective and starts the module.

  4. In the Manual Input view, select the PublishToTopic input stream.

  5. Enter some sample values to populate the tuple's fields.

    Click Send Data (which will trigger the tuple to be sent to the Cluster Topic Publisher adapter and publish the tuple to the topic), and observe that the Subscriber adapter's SubResults output stream received the tuple. Also note that the tuple has been augmented with two fields containing meta-information about this tuple:

    • ordinal (long), which denotes the sequential order in which the tuple was published

    • replay (boolean), which will be set to false unless this tuple is being emitted as part of a Replay command (sent to the Subscriber adapter's command input port, as shown in the next step)

  6. Still in the Manual Input view, select the SubCmd stream and enter Replay as the command field's value with the other fields left null (leaving the begin field null means begin at the oldest published tuple and leaving end null means up to the most recent tuple. Note that these two fields are not present in the sample unless you configure them in the operators).

  7. Click Send Data, which causes the Subscriber to replay the one tuple in the topic's history so far, identical as the one emitted in the previous step only with the isReplay field set to true.

  8. Still in the Manual Input view, select the PubCmd stream and enter Clear as the command field's value. Click Send Data, which causes the Publisher to purge all tuples from the topic's history. You can confirm this by sending another Replay command to the Subscriber.

  9. When done, press F9 or click the Terminate EventFlow Fragment button.

This Sample's Files

This sample's important files include:

  • A single EventFlow module file, clusterpubsub.sbapp.

  • The StreamBase Maven project infrastructure.

Sample Location

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_clusterpubsub

See Default Installation Directories for the default location of studio-workspace on your system.