Skip to content

Commit

Permalink
added $channel->publish method
Browse files Browse the repository at this point in the history
meaning we can now easily publish when we don't have a queue handy
  • Loading branch information
joodie committed Sep 11, 2009
1 parent 5299a2e commit 98e2a95
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions lib/POE/Component/Client/AMQP/Channel.pm
Expand Up @@ -350,6 +350,40 @@ sub exchange {
return 1;
}


=head2 publish ($message, \%opts)
=over 4
Sends a message. In other words, sends a L<Net::AMQP::Protocol::Basic::Publish> followed by a L<Net::AMQP::Protocol::Basic::ContentHeader> and L<Net::AMQP::Frame::Body> containing the body of the message.
Optionally pass %opts, which can override any option in the L<Net::AMQP::Protocol::Basic::Publish> ('ticket', 'exchange', 'routing_key', 'mandatory', 'immediate'), L<Net::AMQP::Frame::Header> ('weight') or L<Net::AMQP::Protocol::Basic::ContentHeader> ('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<create()> call above.
Expand Down
2 changes: 1 addition & 1 deletion lib/POE/Component/Client/AMQP/Queue.pm
Expand Up @@ -229,7 +229,7 @@ sub subscribe {
=over 4
Sends a message to the queue. In other words, sends a L<Net::AMQP::Protocol::Basic::Publish> followed by a L<Net::AMQP::Protocol::Basic::ContentHeader> and L<Net::AMQP::Frame::Body> containing the body of the message.
Sends a message using the queue name as the routing_key. In other words, sends a L<Net::AMQP::Protocol::Basic::Publish> followed by a L<Net::AMQP::Protocol::Basic::ContentHeader> and L<Net::AMQP::Frame::Body> containing the body of the message.
Optionally pass %opts, which can override any option in the L<Net::AMQP::Protocol::Basic::Publish> ('ticket', 'exchange', 'routing_key', 'mandatory', 'immediate'), L<Net::AMQP::Frame::Header> ('weight') or L<Net::AMQP::Protocol::Basic::ContentHeader> ('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.
Expand Down

0 comments on commit 98e2a95

Please sign in to comment.