From 98e2a9569d2bdffc7ed843f58ac582c8e27e23b5 Mon Sep 17 00:00:00 2001 From: Joost Diepenmaat Date: Fri, 11 Sep 2009 13:42:38 +0200 Subject: [PATCH] added $channel->publish method meaning we can now easily publish when we don't have a queue handy --- lib/POE/Component/Client/AMQP/Channel.pm | 34 ++++++++++++++++++++++++ lib/POE/Component/Client/AMQP/Queue.pm | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/POE/Component/Client/AMQP/Channel.pm b/lib/POE/Component/Client/AMQP/Channel.pm index b11daed..8a5e831 100644 --- a/lib/POE/Component/Client/AMQP/Channel.pm +++ b/lib/POE/Component/Client/AMQP/Channel.pm @@ -350,6 +350,40 @@ sub exchange { return 1; } + +=head2 publish ($message, \%opts) + +=over 4 + +Sends a message. In other words, sends a L followed by a L and L containing the body of the message. + +Optionally pass %opts, which can override any option in the L ('ticket', 'exchange', 'routing_key', 'mandatory', 'immediate'), L ('weight') or L ('content_type', 'content_encoding', 'headers', 'delivery_mode', 'priority', 'correlation_id', 'reply_to', 'expiration', 'message_id', 'timestamp', 'type', 'user_id', 'app_id', 'cluster_id') objects. See the related documentation for an explaination of each. + +You will likely want to set exchange or routing_key or both. + +=back + +=cut + +sub publish { + my ($self, $message, $user_opts) = @_; + $user_opts ||= {}; + + $self->do_when_created(sub { + my %opts = ( + content_type => 'application/octet-stream', + %$user_opts, + ); + + $poe_kernel->post($self->{Alias}, server_send => + $self->{server}->compose_basic_publish($message, %opts) + ); + }); + + return $self; +} + + =head1 POE STATES The following are states you can post to to interact with the client. Use the alias defined in the C call above. diff --git a/lib/POE/Component/Client/AMQP/Queue.pm b/lib/POE/Component/Client/AMQP/Queue.pm index a08aa1f..1793c2c 100644 --- a/lib/POE/Component/Client/AMQP/Queue.pm +++ b/lib/POE/Component/Client/AMQP/Queue.pm @@ -229,7 +229,7 @@ sub subscribe { =over 4 -Sends a message to the queue. In other words, sends a L followed by a L and L containing the body of the message. +Sends a message using the queue name as the routing_key. In other words, sends a L followed by a L and L containing the body of the message. Optionally pass %opts, which can override any option in the L ('ticket', 'exchange', 'routing_key', 'mandatory', 'immediate'), L ('weight') or L ('content_type', 'content_encoding', 'headers', 'delivery_mode', 'priority', 'correlation_id', 'reply_to', 'expiration', 'message_id', 'timestamp', 'type', 'user_id', 'app_id', 'cluster_id') objects. See the related documentation for an explaination of each.