Contents
This sample features several demonstrations of StreamBase client programs. The sample consists of two StreamBase server applications and several client programs written in different languages that each enqueue to and dequeue from one of the two server applications. The sample illustrates the following client program scenarios:
Run this ... | Source code provided in: | |||||
---|---|---|---|---|---|---|
Scenario | Server | Dequeuer | Enqueuer | Java | C++ | Python |
Simple Enqueue and Dequeue |
simple.sbapp
|
SimpleDequeuer | SimpleEnqueuer | yes | yes | yes |
Dequeuer with Interceptor |
simple.sbapp
|
InterceptingDequeuer | SimpleEnqueuer | yes | — | — |
Reconnecting Clients |
simple.sbapp
|
ReconnectingDequeuer | ReconnectingEnqueuer | yes | — | — |
Filtered Subscribe Client |
FilteredSubcribe.sbapp
|
FilteredSubscribe |
Feed simulation, FilteredSubscribeTest.sbfs
|
yes | yes | — |
- Simple Enqueue and Dequeue
-
In this scenario,
SimpleEnqueuer
enqueues ten tuples, whileSimpleDequeuer
dequeues the processed tuples. You can keep thesimple.sbapp
server running while you enqueue and dequeue from clients written in all three languages. For example, you can enqueue from the Java enqueuer, then dequeue from the C++ or Python dequeuer. - Dequeuer With Interceptor
-
This scenario illustrates the use of an interceptor Java module in the dequeuer client program. In this case, the interceptor passes only the even-numbered tuples.
- Reconnecting Clients
-
For this scenario, the StreamBase Server instance running
simple.sbapp
is stopped and restarted while the enqueuer and dequeuer programs are running. This demonstrates that the enqueuer and dequeuer client programs can pause, then automatically reconnect to the restarted server.A tuple can be dropped if StreamBase Server emits to an output stream for which there are no subscribers. The dequeue program may miss one or more tuples that have been dropped in this fashion.
- Filtered Subscribe Client
-
This sample demonstrates how to narrow the result set using predicates in the dequeuing client program. Run the
FilteredSubscribe.sbapp
StreamBase server application, and feed input data to it using a feed simulation. You then run theFilteredSubscribe
client program to dequeue filtered results.
The Java code in this sample is delivered only in source code form. To build the code, you must load the sample into StreamBase Studio, which automatically builds the Java code.
To build the C++ client programs on UNIX, invoke targets in the provided Makefile with a Gnu-compatible make command. This requires GCC and G++ 4.2.
The Client sample consists of the files shown in the following table.
File | Description |
---|---|
simple.sbapp
|
A simple StreamBase application with a Map operator that negates its incoming int and double fields, and adds "processed" to its incoming string fields. The input schema includes a field of type tuple with a nested tuple field. |
FilteredSubscribe.sbapp
|
A simple StreamBase application with a pass-through Map operator. |
*.java
|
Java source code for the client enqueue and dequeue programs, placed in
java-src/com.streambase.sample.clients and
automatically compiled by Studio.
|
*.launch
|
Studio launchers for the six Java client programs. The presence of the
.launch files is what places the launchers in
the Run History list, as described below.
|
SimpleEnqueuer.cpp , SimpleDequeuer.cpp , FilteredSubscribe.cpp
|
C++ source code for the client programs. |
SimpleEnqueuer , SimpleDequeuer , FilteredSubscribe
|
UNIX and OS X only. Executable client programs built from the C++ source code. |
Makefile
|
UNIX and OS X only. A makefile to build and run the client programs from C++ source code on UNIX or OS X, using GCC 4.2. |
*.exe
|
Windows only. Executable client
programs built from the C++ source code are provided in the %STREAMBASE_HOME%\sample\client directory and are copied to
your Studio workspace when you load the sample in Studio.
Programs with the
Programs with the |
*.sln
|
Windows only. Solution files for
three versions of Visual Studio:
vc8.sln file with
Visual C++ 9.0.
|
*.vcproj , *.vcxproj
|
Windows only. Project files for
three versions of Visual Studio:
NoteIn the Visual Studio project files, the paths to the StreamBase Include files and libraries are configured for the standard default StreamBase installation directory. You may need to adjust these paths for your installation. |
SimpleEnqueuer.py , SimpleDequeuer.py
|
Python versions of the simple enqueuer and dequeuer programs. See Running the Python Samples. |
FilteredSubscribeTest.sbfs
|
Feed simulation file for the FilteredSubscribe.sbapp StreamBase application.
|
FilteredSubscribeTest.csv
|
CSV data file used by the above feed simulation file. |
The Java sample clients are intended to be run in StreamBase Studio, while the C++ and Python sample clients are intended to be run in UNIX terminal windows or Windows Command Prompt windows, as described in Running the C++ or Python Client Samples in Terminal Windows.
The sample has no provision for running the Java sample clients at the command line,
but experienced Java developers can do so by adding the java-bin
directory to the classpath.
This section has the following subsections:
When you load this sample in Studio, the sample places launchers for the Java client sample programs in Studio's Run History list. For each sample application, the overall procedure is:
-
Run a provided StreamBase application in Studio. The StreamBase application accepts input from the Manual Input or Feed Simulations view, and shows output in the Application Output view, as normal.
-
Use one of the launchers in the Run History list to run one or more Java client programs at the same time the StreamBase application is running. Java client programs show their output in one or more Console views.
Run a Java client launcher from the Run History list using one of the following methods:
-
From the Studio top-level menu, invoke
→ , and select the specified launcher from the list. -
Open the Run Configurations dialog, select the specified launcher from the Java application category, then click
. -
Click the down-arrow next to the Run button
in the Studio toolbar, and select the specified launcher from the list.
The Java client launchers placed in the Run History list presume that Studio is running the StreamBase application on port 10000, which is the installed default port for StreamBase application launches. Before you proceed, use these steps to confirm that port 10000 is the default launch port:
-
Open
→ . -
In the left side navigation column, open
→ . -
Confirm that the Default Port setting is 10000. If not, change it to 10000.
-
Click
.
When you run a Java program's launcher, it prints output lines to the Console view. There is one Console view for each running program; switch between Console views with the drop-down arrow of the Display Selected Console button.
![]() |
Use the Remove All Terminated Launches button to close unneeded Console views.
![]() |
Follow these steps to run this scenario in StreamBase Studio:
-
In the Package Explorer, double-click to open the
simple.sbapp
application. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
Open the Run History list as described in Introduction and Setup, and select the
SimpleDequeuer
launcher. This runs the Java program of that name, which connects to the StreamBase Server instance runningsimple.sbapp
. The Console view reports:SimpleDequeuer: Ready
-
Open the Run History list again and select the
SimpleEnqueuer
launcher. This Java program connects tosimple.sbapp
, emits ten tuples, then exits. The dequeuer's Console view reports:SimpleDequeuer: Ready SimpleDequeuer: dequeue: -1,Tuple #1 processed!,-0.1,"0,processed: Tuple #1" SimpleDequeuer: dequeue: -2,Tuple #2 processed!,-0.2,"4,processed: Tuple #2" SimpleDequeuer: dequeue: -3,Tuple #3 processed!,-0.3,"13,processed: Tuple #3" SimpleDequeuer: dequeue: -4,Tuple #4 processed!,-0.4,"32,processed: Tuple #4" SimpleDequeuer: dequeue: -5,Tuple #5 processed!,-0.5,"62,processed: Tuple #5" SimpleDequeuer: dequeue: -6,Tuple #6 processed!,-0.6,"107,processed: Tuple #6" SimpleDequeuer: dequeue: -7,Tuple #7 processed!,-0.7,"171,processed: Tuple #7" SimpleDequeuer: dequeue: -8,Tuple #8 processed!,-0.8,"256,processed: Tuple #8" SimpleDequeuer: dequeue: -9,Tuple #9 processed!,-0.9,"364,processed: Tuple #9" SimpleDequeuer: dequeue: -10,Tuple #10 processed!,-1.0,"500,processed: Tuple #10"
-
Use the Debug view in the upper right to manage the running programs. Select a terminated program, right-click and relaunch it from the context menu. Use the context menu and the buttons of the Debug view to restart or close the Java programs at will.
-
When done, press F9 or click the
Stop Running Application button. This closes the StreamBase application and all Java client programTableOperators.
Follow these steps to run this scenario in StreamBase Studio:
-
In the Package Explorer, double-click to open the
simple.sbapp
application. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
Open the Run History list as described in Introduction and Setup, and select the
InterceptingDequeuer
launcher. This runs the Java program of that name, which connects to the StreamBase Server instance runningsimple.sbapp
. The Console view reports:InterceptingDequeuer: Ready
-
Open the Run History list again and select the
SimpleEnqueuer
launcher. This Java program connects tosimple.sbapp
, emits ten tuples, then exits. The dequeuer's Console view reports:InterceptingDequeuer: Ready InterceptingDequeuer: dequeue [sb://localhost/]: -2,Tuple #2 processed!,-0.2,"4,processed: Tuple #2" InterceptingDequeuer: dequeue [sb://localhost/]: -4,Tuple #4 processed!,-0.4,"32,processed: Tuple #4" InterceptingDequeuer: dequeue [sb://localhost/]: -6,Tuple #6 processed!,-0.6,"107,processed: Tuple #6" InterceptingDequeuer: dequeue [sb://localhost/]: -8,Tuple #8 processed!,-0.8,"256,processed: Tuple #8" InterceptingDequeuer: dequeue [sb://localhost/]: -10,Tuple #10 processed!,-1.0,"500,processed: Tuple #10"
Notice that the Intercepting Dequeuer program only processes tuples with an even number in the incoming int field.
-
As with the first scenario, use the Debug view in the upper right to manage the running programs.
-
When done, press F9 or click the
Stop Running Application button. This closes the StreamBase application and all Java client programs.
Follow these steps to run this scenario in StreamBase Studio:
-
In the Package Explorer, double-click to open the
simple.sbapp
application. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
Open the Run History list as described in Introduction and Setup, and select the
ReconnectingDequeuer
launcher. This runs the Java program of that name, which connects to the StreamBase Server instance runningsimple.sbapp
. The Console view reports:ReconnectingDequeuer: Connected to StreamBase at [sb://localhost/]
-
Open the Run History list again and select the
ReconnectingEnqueuer
launcher. This Java program connects tosimple.sbapp
, emits one tuple every five seconds, exiting after the tenth tuple. The dequeuer's Console view reports:ReconnectingEnqueuer: Connected to StreamBase at [sb://localhost/] ReconnectingEnqueuer: enqueue: Tuple #1,1,0.1,"0.05,""10,#1""" ReconnectingEnqueuer: enqueue: Tuple #2,2,0.2,"0.1,""20,#2""" ...
-
While the enqueuer is running, press F9 or click the
Stop Running Application button. The following events occur:
-
The
simple.sbapp
application stops and Studio returns to the SB Authoring perspective. -
The Reconnecting Dequeuer immediately detects that the connection is down and enter its reconnection loop.
-
The Reconnecting Enqueuer sends one more tuple without an error, but then receives a network exception when sending the following tuple. It then enters its reconnection loop.
-
-
Click the
Run button to restart
simple.sbapp
. Both client programs detect the restarted server and continue processing tuples. -
When done, press F9 or click the
Stop Running Application button. This closes the StreamBase application and all Java client programs.
Follow these steps to run this scenario in StreamBase Studio:
-
In the Package Explorer, double-click to open the
FilteredSubscribe.sbapp
application. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
Open the Run History list as described in Introduction and Setup, and select the
FilteredSubscribe
launcher. This runs the Java program of that name, which connects toFilteredSubscribe.sbapp
. The Console view reports:FilteredSubscribe: Ready
-
Bring the Application Output view to the foreground so that you can see tuples exiting from the
FilteredSubscribe.sbapp
application. -
Select the Feed Simulations tab, select the
FilteredSubscribeTest.sbfs
feed simulation line, and click . The feed simulation runs to completion, showing five tuples output on the application'sOutputStream1
. -
Compare the dequeuer's Console window, which shows seven lines of output. The
FilteredSubscribe
program creates two new output streams,IBM_gt_85
andMSFT_big_Trade
, in addition toOutputStream1
.FilteredSubscribe: Ready FilteredSubscribe: dequeue: GE,35.0,200 from stream: OutputStream1 FilteredSubscribe: dequeue: IBM,84.5,300 from stream: OutputStream1 FilteredSubscribe: dequeue: IBM,88.0,200 from stream: IBM_gt_85 FilteredSubscribe: dequeue: IBM,88.0,200 from stream: OutputStream1 FilteredSubscribe: dequeue: MSFT,25.0,300 from stream: OutputStream1 FilteredSubscribe: dequeue: MSFT,24.75,1003 from stream: MSFT_big_Trade FilteredSubscribe: dequeue: MSFT,24.75,1003 from stream: OutputStream1
-
When done, press F9 or click the
Stop Running Application button. This closes the StreamBase application and all Java client programs.
If you have access to StreamBase Studio, run all four Java scenarios in Studio before running the C++ or Python versions at the command prompt, to get a feel for what to expect.
You can mix and match different library implementations of SimpleEnqueuer
and SimpleDequeuer
. For
example, you can dequeue with a C++ client and enqueue with a Python client.
On Windows, you must use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.
This section has the following subsections:
Follow these steps to run the C++ Simple Enqueue and Dequeue scenario in terminal windows:
-
Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to your workspace copy of the sample, as described above.
-
Build the C++ samples as follows:
-
On UNIX, including OS X, in window 1, type:
make all
-
On Windows, load the
-
-
In window 1, type:
sbd simple.sbapp
-
In window 2 on UNIX, type:
./SimpleDequeuer
For Windows, type:
SimpleDequeuer
Window 2 now shows:
SimpleDequeuer: Ready
-
In window 3 on UNIX, type:
./SimpleEnqueuer
For Windows, type:
SimpleEnqueuer
-
In window 2, look for output lines from the dequeuer:
SimpleDequeuer: Ready SimpleDequeuer: dequeue: -1,Tuple #1 processed!,-0.1,"0,processed: Tuple #1" SimpleDequeuer: dequeue: -2,Tuple #2 processed!,-0.2,"4,processed: Tuple #2" SimpleDequeuer: dequeue: -3,Tuple #3 processed!,-0.3,"13,processed: Tuple #3" SimpleDequeuer: dequeue: -4,Tuple #4 processed!,-0.4,"32,processed: Tuple #4" SimpleDequeuer: dequeue: -5,Tuple #5 processed!,-0.5,"62,processed: Tuple #5" SimpleDequeuer: dequeue: -6,Tuple #6 processed!,-0.6,"107,processed: Tuple #6" SimpleDequeuer: dequeue: -7,Tuple #7 processed!,-0.7,"171,processed: Tuple #7" SimpleDequeuer: dequeue: -8,Tuple #8 processed!,-0.8,"256,processed: Tuple #8" SimpleDequeuer: dequeue: -9,Tuple #9 processed!,-0.9,"364,processed: Tuple #9" SimpleDequeuer: dequeue: -10,Tuple #10 processed!,-1.0,"500,processed: Tuple #10"
-
In window 3, type the following command to terminate the server and dequeuer:
sbadmin shutdown
Follow these steps to run the C++ Filtered Subscribe scenario in terminal windows:
-
Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to your workspace copy of the sample, as described above.
-
In window 1, type:
sbd FilteredSubscribe.sbapp
-
In window 2 on UNIX, type:
./FilteredSubscribe
For Windows, type:
FilteredSubscribe
Window 2 now shows:
FilteredSubscribe: Ready
-
In window 3, type:
sbfeedsim FilteredSubscribeTest.sbfs
-
Compare the output lines in windows 2 and 3. Notice that there are five lines from the feed simulation in window 3, but the FilteredSubscribe client program has added two extra output ports:
FilteredSubscribe: Ready FilteredSubscribe: dequeue: GE,35.0,200 from stream: OutputStream1 FilteredSubscribe: dequeue: IBM,84.5,300 from stream: OutputStream1 FilteredSubscribe: dequeue: IBM,88.0,200 from stream: IBM_gt_85 FilteredSubscribe: dequeue: IBM,88.0,200 from stream: OutputStream1 FilteredSubscribe: dequeue: MSFT,25.0,300 from stream: OutputStream1 FilteredSubscribe: dequeue: MSFT,24.75,1003 from stream: MSFT_big_Trade FilteredSubscribe: dequeue: MSFT,24.75,1003 from stream: OutputStream1
-
In window 3, type the following command to terminate the server and dequeuer:
sbadmin shutdown
Before running the Python sample clients, make sure your Python environment is configured as described in Creating Python Clients.
Follow these steps to run the C++ Simple Enqueue and Dequeue scenario in terminal windows:
-
Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to your workspace copy of the sample, as described above.
-
In window 1, type:
sbd simple.sbapp
-
In window 2 on UNIX, type:
./SimpleDequeuer.py
For Windows, type:
python SimpleDequeuer
-
In window 3 on UNIX, type:
./SimpleEnqueuer.py
For Windows, type:
python SimpleEnqueuer
-
In window 2, look for output lines from the dequeuer.
-
In window 3, type the following command to terminate the server and dequeuer:
sbadmin shutdown
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, click
→ . -
Select this application from the Applications list.
-
Click OK.
StreamBase Studio creates a project for each sample.
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 the permission problems that can occur when trying to work with the initially installed location of the sample. The default workspace location for this sample is:
studio-workspace
/sample_client
See Default Installation
Directories for the location of studio-workspace
on your system.
In the default TIBCO StreamBase installation, this sample's files are initially installed in:
streambase-install-dir
/sample/client
See Default Installation
Directories for the location of streambase-install-dir
on your system. This location
may require administrator privileges for write access, depending on your platform.