Differences between revisions 1 and 2
Revision 1 as of 2009-04-29 04:25:45
Size: 1374
Editor: JonSchutz
Comment:
Revision 2 as of 2009-09-20 23:47:14
Size: 1376
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
An example using Thrift and Scribe (see [http://notes.jschutz.net/109/perl/perl-client-for-facebooks-scribe-logging-software here for more details about building the perl scribe client]). An example using Thrift and Scribe (see [[http://notes.jschutz.net/109/perl/perl-client-for-facebooks-scribe-logging-software|here for more details about building the perl scribe client]]).

An example using Thrift and Scribe (see here for more details about building the perl scribe client).

The example program reads one line at a time from stdin and sends to a scribe instance running locally on port 1465.

      #! /usr/bin/perl

      use Scribe::Thrift::scribe;
      use Thrift::Socket;
      use Thrift::FramedTransport;
      use Thrift::BinaryProtocol;
      use strict;
      use warnings;

      my $host = 'localhost';
      my $port = 1465;
      my $cat = $ARGV[0] || 'test';

      my $socket = Thrift::Socket->new($host, $port);
      my $transport = Thrift::FramedTransport->new($socket);
      my $proto = Thrift::BinaryProtocol->new($transport);

      my $client = Scribe::Thrift::scribeClient->new($proto, $proto);
      my $le = Scribe::Thrift::LogEntry->new({ category => $cat });

      $transport->open();

      while (my $line = <>) {
          $le->message($line);
          my $result = $client->Log([ $le ]);
          if ($result == Scribe::Thrift::ResultCode::TRY_LATER) {
              print STDERR "TRY_LATER\n";
          }
          elsif ($result != Scribe::Thrift::ResultCode::OK) {
              print STDERR "Unknown result code: $result\n";
          }
      }

      $transport->close();

ThriftUsagePerl (last edited 2009-09-20 23:47:14 by localhost)