Skip to content

Instantly share code, notes, and snippets.

@domm
Created December 7, 2012 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domm/4232328 to your computer and use it in GitHub Desktop.
Save domm/4232328 to your computer and use it in GitHub Desktop.
Simple Plack Server that publises ZeroMQ messages
#!/usr/bin/env perl
use 5.016;
use Plack::Runner qw();
use ZMQ::LibZMQ3;
use ZMQ::Constants qw(ZMQ_PUB);
my $context = zmq_init();
my $publisher = zmq_socket($context, ZMQ_PUB);
zmq_bind($publisher, 'tcp://*:5556');
my $app = sub {
my $env = shift;
my $path = $env->{PATH_INFO};
zmq_send( $publisher, "request $path" );
return [
'200',
[ 'Content-Type' => 'text/plain' ],
[ "You requested: $path" ],
];
};
my $runner = Plack::Runner->new;
$runner->parse_options(@ARGV);
$runner->run($app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment