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 more 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 FileLoad StreamBase Sample.

  • Type active to narrow the list of options.

  • Select Cluster Publisher and Subscriber Operators from the Extending StreamBase category.

  • Click OK.

StreamBase Studio creates a project for the sample.

This Sample's Files

This sample has the following files:

  • The sample's EventFlow application, clusterpubsub.sbapp, with its sidecar clusterpubsub.sblayout file.

Running This Sample in StreamBase Studio

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

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

  2. Open the src/main/eventflow folder.

  3. Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).

  4. Open the named application file and click the Run button. This opens the SB Test/Debug perspective and starts the application.

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

    If red marks do not resolve themselves in a moment, select the project and right-click MavenUpdate Project from the context menu.

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

  6. 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

    • isReplay (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)

  7. 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"). Click Send Data, which will cause 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 will cause the Publisher to purge all tuples from the topic's history. This can be confirmed by sending another Replay command to the Subscriber.

  9. When done, press F9 or click the Stop Running Application button.

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.