Getting started

Write, compile, and run a "Hello, World" SPL application.

In this tutorial, you will:

  1. Write a "Hello, World" stream application
  2. Compile the application using the Streams Compiler (sc)
  3. Run the application

Before you begin

Procedure

  1. 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
  2. Create a directory called splhello.

    For example, use the following commands:

    mkdir splhello
    cd splhello
  3. Using your text editor, create a file named HelloWorld.spl in the splhello directory.
  4. 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:

    1. Declares a main composite operator called HelloWorld.
    2. Starts a data flow graph with the graph clause.
    3. Invokes a Beacon operator to produce a stream called Hi whose tuples have one attribute, message, of type rstring. The invocation is configured to:
      1. Produce only one tuple
      2. Output into the Hi stream the string "Hello, World!"
    4. Invokes a Custom operator which reads from stream Hi. The invocation does not output any streams evident by the () and is named Sink. Sink is configured to print the contents of the message attribute when data from the Hi stream is received.
  5. 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.

  6. Run the application:
    ./output/bin/standalone

    It prints "Hello, World!" to the console and exits the program.

What to do next

Continue to the Stream processing tutorial to learn about the power of stream processing applications and run an application in a distributed environment.