Created
December 7, 2012 10:18
-
-
Save domm/4232328 to your computer and use it in GitHub Desktop.
Simple Plack Server that publises ZeroMQ messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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