Contents
The StreamBase .NET client sample contains three C# and one VB.NET applications that enqueue tuples to, and dequeue tuples from, a StreamBase application. The StreamBase application performs a simple Map operation on the incoming tuples. While the operation is trivial, the sample demonstrates how the StreamBase .NET API enables client applications to be created in a .NET-compatible language that runs with a StreamBase application.
Note
The .NET API and this sample are only available in the StreamBase installation for Microsoft Windows. You can run the pre-built samples without having Visual Studio .NET installed. However, they require version 2.0 or later of the .NET Framework, which can be downloaded from Microsoft's web site.
This topic describes the StreamBase .NET client sample.
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, click → .
-
Select the
dotnetsample from the Client APIs group. -
Click OK.
StreamBase Studio creates a project for this sample.
By default, the sample files are installed in:
C:\Program Files\StreamBase Systems\StreamBase
.n.m\sample\dotnet
When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace. StreamBase Systems recommends that you use the workspace copy of the sample. In the default installation, the path to this sample in your Studio workspace is:
Windows XP: C:\Documents and Settings\username\My Documents\StreamBase Studion.mWorkspace\ sample_dotnet Windows Vista: C:\Users\username\Documents\StreamBase Studion.mWorkspace\ sample_dotnet
The sample has the following files:
-
A StreamBase application,
dotnet.sbapp. -
One enqueuer and three dequeuer programs that use the StreamBase .NET API.
-
Microsoft Visual Studio .NET solution and project files, which can be used to build all of the sample source code. (In the Visual Studio project files, the paths to the StreamBase include files and libraries are configured for the standard default installation directory. You may need to adjust these paths for your PC.)
To run this sample using StreamBase Studio:
Note
Running the forms-based sample dequeuer, bin\SimpleDequeuerForm.exe, is not supported from
StreamBase Studio.
-
In the Package Explorer, double-click to open the
dotnet.sbappapplication. 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 a StreamBase Command Prompt window, and navigate to the directory where the sample is installed, or to your workspace copy of the sample, as described above.
-
In the Command Prompt window, run the enqueuer by typing:
bin\SimpleEnqueuer.exe -
Back in Studio, observe that ten tuples appear in the Application Output view.
-
In the Command Prompt window, run the dequeuer by typing:
bin\SimpleDequeuer.exeorbin\SimpleDequeuerVB.exe -
Back in Studio, in the Manual Input view, fill in the three fields and click .
-
Observe that a modified version of the tuple is dequeued by the simple dequeuer sample program running in the Command Prompt window.
-
When done, press F9 or click the
Stop Running Application button.
-
Open three StreamBase Command Prompt windows. In each window, navigate to the directory where the sample is installed, or to your workspace copy of the sample, as described above.
-
In window 1, run the StreamBase Server on
dotnet.sbapp:sbd dotnet.sbapp -
In window 2, enter one of the following commands to run the dequeuer:
-
Console dequeuer command:
bin\SimpleDequeuer.exeorbin\SimpleDequeuerVB.exe -
Windows form-based dequeuer command:
bin\SimpleDequeuerForm.exe
-
-
If you are using the form-based dequeuer, click .
-
In window 3, enter the following command to run the enqueuer:
bin\SimpleEnqueuer.exe -
Observe that tuples are displayed by the dequeuer. In the case of the form-based dequeuer, the last tuple dequeued is displayed.
-
Run
sbadmin shutdownto close the server.
-
Launched Visual Studio.
-
Created a new solution file named
DotNetSamples. -
Added three C# projects to the solution: SimpleEnqueuer, SimpleDequeuer, and SimpleDequeuerForm. The first two are Console Applications, and the third is a Windows Application.
-
Added references from each of the four projects to the following StreamBase-supplied assembly:
sbclient.dll. This assembly is placed inC:\Program Files\StreamBase Systems\StreamBasewhen StreamBase is installed..n.m\bin -
Added a class file to each of the projects to hold the application code.
-
At the top of each class file, added
usingstatements to access the StreamBase client .NET API namespaces:using System; using StreamBase.SB; using StreamBase.SB.Client;Note that the form-based dequeuing application uses several additional namespaces.
-
In the enqueue and dequeue clients, created a
StreamBaseClientobject, representing a connection to the StreamBase Server:string SERVER="sb://localhost:10000"; StreamBaseURI uri = new StreamBaseURI(SERVER);
-
In the enqueue client:
-
Created a tuple to be enqueued to the StreamBase Server:
string INPUT_STREAM="InputStream1"; StreamProperties props = client.GetStreamProperties(INPUT_STREAM); Tuple t = props.GetSchema().CreateTuple();
-
Repeatedly initialized the tuple and enqueued it to the StreamBase Server:
for (int i = 1; i <= NUM_TUPLES; i++) { t.SetInt(FIELD1, i); t.SetString(FIELD2, "Tuple #"+i); t.SetDouble(FIELD3, i / 10.0); client.Enqueue("InputStream1", t);}
-
-
In the dequeue client:
-
Repeatedly dequeued a sequence of tuples from the StreamBase Server:
DequeueResult dr = null; while((dr = client.Dequeue()) == DequeueResult.GOOD) { . . } -
Processed each tuple in the sequence:
foreach(Tuple tuple in dr) { Console.WriteLine("dequeue: " + tuple.ToString()); }
-
-
Launched StreamBase Studio.
-
In the SB Authoring perspective, created the
dotnetproject: From the top menu, selected → , entereddotnetin the Project name field, and clicked . -
From the top menu, selected → → . Selected the
dotnetproject, and enteredsimple.sbappfor the diagram name. -
Created an input stream:
-
Dragged an input stream from the palette to the canvas.
-
Selected the input stream's icon on the canvas, which invoked the Input Stream Properties view.
-
On the Edit Schema tab, added:
Field Name Type Size mystring string 32 myint int 4 mydouble double 8
-
-
Set up the Map operator:
-
Dragged a Map operator from the palette to the canvas and opened its Properties view.
-
Dragged a connector from the Input Stream to the input of the
Map1operator. -
On the Output Settings tab, selected the
explicitly specified fieldsoption. -
Clicked the button three times to add three rows. Edited the row fields as follows:
Output Field Name Expression myint -myint mystring mystring+"processed!" mydouble -mydouble -
Clicked the button to add another row:
-
Action:
Add -
Field Name :
randomDouble -
Exression:
calljava('java.lang.Math', 'random')
-
-
-
Created an output stream:
-
Dragged an output stream from the palette to the canvas.
-
Connected the
Map1operator to the output stream.
-
