Contents
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.
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.
In StreamBase Studio, import this sample with the following steps:
-
From the top-level menu, select
> . -
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
.
StreamBase Studio creates a project for the sample.
The steps to run this sample in Studio are as follows:
-
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
> from the context menu. -
Open the
src/main/eventflow/
folder.packageName
-
Open the
clusterpubsub.sbapp
file and click the Run button. This opens the SB Test/Debug perspective and starts the module. -
In the Manual Input view, select the
PublishToTopic
input stream. -
Enter some sample values to populate the tuple's fields.
Click
(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'sSubResults
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 tofalse
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)
-
-
Still in the Manual Input view, select the
SubCmd
stream and enterReplay
as thecommand
field's value with the other fields left null (leaving thebegin
field null meansbegin at the oldest published tuple
and leavingend
null meansup to the most recent tuple
. Note that these two fields are not present in the sample unless you configure them in the operators). -
Click
, 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 theisReplay
field set totrue
. -
Still in the Manual Input view, select the
PubCmd
stream and enterClear
as thecommand
field's value. Click , which causes the Publisher to purge all tuples from the topic's history. You can confirm this by sending anotherReplay
command to the Subscriber. -
When done, press F9 or click the Terminate EventFlow Fragment button.
This sample's important files include:
-
A single EventFlow module file,
clusterpubsub.sbapp
. -
The StreamBase Maven project infrastructure.
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.