An example that demonstrates how a simple output adapter subscribes to messages in the Sybase CEP stream.
The following example receives data from a Sybase CEP stream and publishes that data.
The full listing with line numbers is below:
1 use C8::Subscriber;
2
3 # Get command-line arguments.
4 my $usage = "$0 <uri>"; # Usage message to use if err
5 my $uri = shift or die "ERR: uri is not specified.\nUsage: $usage\n";
6
7 # Create a subscriber object.
8 my $subscriber = C8::Subscriber->new();
9 $subscriber->connect($uri) or die "ERR: cannot subscribe to '$uri'\n";
10
11 # First, print column names.
12 print join(',', $subscriber->column_names()) . "\n";
13
14 # then print each message row
15 while(1) {
16 my $tuple = $subscriber->read_tuple or last;
17 print "Ts: " . localtime($tuple->timestamp) . "\n";
18 print "Fields: " . join(',', $tuple->fields) . "\n";
19 }
Line 1 loads the Sybase CEP module C8::Subscriber. The module must be available in the Perl include path. See Perl documentation for more details.
Lines 3-5 gets the Sybase CEP Stream URI from the command line.
Lines 7-9 creates Sybase CEP subscriber and connect to the Sybase CEP stream with the given URI.
Lines 11-12 get the list of column names from the Sybase CEP Server and print it out.
Lines 15-19 comprise the main loop.
Line 16 reads the new tuple.
Lines 17-18 prints the tuple.