This example demonstrates a simple input adapter that publishes generated messages to the Sybase CEP Stream.
The Perl program connects to the Sybase CEP stream by using a URI specified in the command line. The stream schema is assumed to have exactly two fields ('Symbol' and 'Price') and the generated messages look like the following:
Symbol1, 1
Symbol2, 2
Symbol3, 3
...
The full listing with line numbers is below:
1  use C8::Publisher;
2  use C8::Tuple;
3
4  # Get command-line argument(s).
5  my $usage = "$0 <uri>";  # Usage msg to display if err
6  my $uri = shift or 
 die "ERROR: URI is missing.\nUsage: $usage\n";
7
8  # Create a publisher object.
9  my $publisher = C8::Publisher->new();
10 $publisher->connect($uri) or 
 die "ERROR: cannot publish to '$uri'\n";
11 
12 # Create tuples and publish them.
13 my @field_names = ('Symbol', 'Price');
14 # Loop "forever"...
15 for(my $n = 0; ; $n++) {
16     # create tuple
17     my $tuple = C8::Tuple->new(@field_names);
18
19     # Set tuple fields, e.g. to "Symbol1", 1.
20     $tuple->fields('Symbol' . $n, $n);
21 
22     # publish tuple to the stream
23     $publisher->write_tuple($tuple) or last;
24
25     sleep(1); # sleep a little bit
26 }
            Lines 1-2 load the Sybase CEP modules C8::Tuple and C8::Publisher. The modules need to be available in the Perl include path. See Perl documentation for more details.
Lines 4-6 get the Sybase CEP Stream URI from the command line.
Lines 8-10 create Sybase CEP publisher and connect to the Sybase CEP Stream with the given URI.
Lines 12-13 declare the list of field names in the tuple.
Lines 15-26 comprise the main loop: create a tuple, publish it to Sybase CEP, sleep.
Lines 16-17 create a tuple with the given list of fields.
Lines 19-20 set tuple fields to the given values.
Lines 22-23 publish a newly created tuple.
Line 25 instructs the adapter to sleep.