Permalink
Browse files

Change server to hostname/port

  • Loading branch information...
1 parent 3d577cf commit 51dfafe0d9b60e1d208a7775dd63ed4aa6406ea9 @bobtfish bobtfish committed Jun 10, 2012
View
@@ -1,6 +1,10 @@
- Remove Message::Passing::Redis::Types - types we need are
now in the core Message::Passing type library.
+ - Change 'server' attribute to 'hostname' and 'port' attributes,
+ with the hostname being mandatory and the port having a default,
+ to match other components.
+
0.004
- Allow a string for a single topic, rather than forcing a list
of one item in Message::Passing::Input::Redis
@@ -69,17 +69,21 @@ Message::Passing::Input::Redis - A Redis consumer for Message::Passing
=head1 SYNOPSIS
- $ message-passing --output STDOUT --input Redis --input_options '{"topics":["foo"],"server":"127.0.0.1:6379"}'
+ $ message-passing --output STDOUT --input Redis --input_options '{"topics":["foo"],"hostname":"127.0.0.1","port":"6379"}'
=head1 DESCRIPTION
A simple subscriber a Redis PubSub topic
=head1 ATTRIBUTES
-=head2 server
+=head2 hostname
-The hostname and port number of the Redis server. Defaults to C<< 127.0.0.1:6379 >>.
+The hostname of the Redis server. Required.
+
+=head2 port
+
+The port number of the Redis server. Defaults to 6379.
=head2 topics
@@ -30,17 +30,21 @@ Message::Passing::Output::Redis - A Redis publisher for Message::Passing
=head1 SYNOPSIS
- $ message-passing --input STDIN --output Redis --output_options '{"topic":"foo","server":"127.0.0.1:6379"}'
+ $ message-passing --input STDIN --output Redis --output_options '{"topic":"foo","hostname":"127.0.0.1","port":"6379"}'
=head1 DESCRIPTION
A simple message output which publishes messages to a Redis PubSub topic.
=head1 ATTRIBUTES
-=head2 server
+=head2 hostname
-The hostname and port number of the Redis server. Defaults to C<< 127.0.0.1:6379 >>.
+The hostname of the Redis server. Required.
+
+=head2 port
+
+The port number of the Redis server. Defaults to 6379.
=head2 topic
@@ -15,11 +15,11 @@ Message::Passing::Redis - Produce or consume messages by Redis PubSub
=head1 SYNOPSIS
# Terminal 1:
- $ message-passing --input STDIN --output Redis --output_options '{"topic":"foo","server":"127.0.0.1:6379"}'
+ $ message-passing --input STDIN --output Redis --output_options '{"topic":"foo","hostname":"127.0.0.1","port":"6379"}'
{"data":{"some":"data"},"@metadata":"value"}
# Terminal 2:
- $ message-passing --output STDOUT --input Redis --input_options '{"topics":["foo"],"server":"127.0.0.1:6379"}'
+ $ message-passing --output STDOUT --input Redis --input_options '{"topics":["foo"],"hostname":"127.0.0.1","port":"6379"}'
{"data":{"some":"data"},"@metadata":"value"}
=head1 DESCRIPTION
@@ -6,18 +6,24 @@ use namespace::autoclean;
with 'Message::Passing::Role::ConnectionManager';
-has server => (
+has hostname => (
is => 'ro',
isa => 'Str',
required => 1,
);
+has port => (
+ is => 'ro',
+ isa => 'Int',
+ default => 6379,
+);
+
sub _build_connection {
my $self = shift;
weaken($self);
my $client = Redis->new(
encoding => undef,
- server => $self->server,
+ server => sprintf("%s:%s", $self->hostname, $self->port),
);
# Delay calling set_connected till we've finished building the client
my $i; $i = AnyEvent->idle(cb => sub {
@@ -2,18 +2,24 @@ package Message::Passing::Redis::Role::HasAConnection;
use Moose::Role;
use namespace::autoclean;
-has server => (
+has hostname => (
is => 'ro',
isa => 'Str',
- default => '127.0.0.1:6379',
+ required => 1,
+);
+
+has port => (
+ is => 'ro',
+ isa => 'Int',
+ default => 6379,
);
with 'Message::Passing::Role::HasAConnection';
use Message::Passing::Redis::ConnectionManager;
sub _build_connection_manager {
my $self = shift;
Message::Passing::Redis::ConnectionManager->new(map { $_ => $self->$_() }
- qw/ server /
+ qw/ hostname port /
);
}
View
@@ -9,6 +9,7 @@ use Message::Passing::Output::Test;
my $cv = AnyEvent->condvar;
my $input = Message::Passing::Input::Redis->new(
+ hostname => "127.0.0.1",
topics => "log_stash.test",
output_to => Message::Passing::Output::Test->new(
cb => sub { $cv->send }
@@ -17,6 +18,7 @@ my $input = Message::Passing::Input::Redis->new(
my $output = Message::Passing::Output::Redis->new(
topic => "log_stash.test",
+ hostname => "127.0.0.1",
);
my $this_cv = AnyEvent->condvar;
@@ -33,6 +35,7 @@ is_deeply([$input->output_to->messages], ['bar']);
my $other_output = Message::Passing::Output::Redis->new(
topic => "log_stash.foo",
+ hostname => "127.0.0.1",
);
$cv = AnyEvent->condvar;
@@ -41,6 +44,7 @@ my $other_input = Message::Passing::Input::Redis->new(
output_to => Message::Passing::Output::Test->new(
cb => sub { $cv->send }
),
+ hostname => "127.0.0.1",
);
$this_cv = AnyEvent->condvar;
@@ -49,6 +53,11 @@ $timer = AnyEvent->timer(after => 2, cb => sub {
$this_cv->send;
});
$this_cv->recv;
+$timer = AnyEvent->timer(after => 10, cb => sub {
+ undef $timer;
+ fail "Timed out";
+ $cv->throw;
+});
$output->consume('quux');
$other_output->consume('fnord');
$cv->recv;

0 comments on commit 51dfafe

Please sign in to comment.