Getting started
Write, compile, and run a "Hello, World" SPL application.
In this tutorial, you will:
- Write a "Hello, World" stream application
- Compile the application using the Streams Compiler (
sc
) - Run the application
Before you begin
- Download and install Teracloud® Streams
- Open a Bash command terminal
- Open a text editor
Procedure
-
Set up your environment for Streams.
In your command terminal, source the streamsprofile.sh file under Streams installation directory. For example:
source streams-install-directory/bin/streamsprofile.sh
-
Create a directory called splhello.
For example, use the following commands:
mkdir splhello cd splhello
- Using your text editor, create a file named HelloWorld.spl in the splhello directory.
-
Paste the following code into your file and save it:
composite HelloWorld { graph stream<rstring message> Hi = Beacon() { param iterations: 1u; output Hi: message = "Hello, World!"; } () as Sink = Custom(Hi) { logic onTuple Hi: printStringLn(message); } }
This SPL code does the following:
- Declares a main composite operator called
HelloWorld
. - Starts a data flow graph with the
graph
clause. - Invokes a
Beacon
operator to produce a stream calledHi
whose tuples have one attribute,message
, of type rstring. The invocation is configured to:- Produce only one tuple
- Output into the
Hi
stream the string "Hello, World!"
- Invokes a
Custom
operator which reads from streamHi
. The invocation does not output any streams evident by the()
and is namedSink
.Sink
is configured to print the contents of the message attribute when data from theHi
stream is received.
- Declares a main composite operator called
-
Compile the code.
In the splhello directory, run the following command:
sc -M HelloWorld
The command instructs the SPL compiler to create a stream application from the
HelloWorld
main composite operator. The compiler generates several artifacts including a stand-alone executable file of the application. -
Run the application:
./output/bin/standalone
It prints "Hello, World!" to the console and exits the program.