Net::RabbitMQ::Channel - use rabbitmq, OOP style
use Net::RabbitMQ::Channel; my $channel = Net::RabbitMQ::Channel->new (1, { hosts => { rabbit1 => {user => 'guest', pass => 'guest'}, rabbit2 => {user => 'guest', pass => 'guest'} } }); my $exchange = $channel->exchange_declare ( 'test.x', exchange_type => "topic", ); my $publisher_key = 'test.*'; # consumer part my $queue = $channel->queue_declare ( 'test.q', exclusive => 0, ); $queue->bind ($exchange, $publisher_key); # publisher part $exchange->publish ($publisher_key, $message, app_id => 'test', timestamp => time ); # consumer part my $message = $queue->get;
my $channel = Net::RabbitMQ::Channel->new (1, { # mandatory hosts => {host_name => {user => 'user_name', pass => 'password'}}, # optional });
when creating Net::RabbitMQ::Channel you must provide channel number and configuration options.
in the current version only 'hosts' key is supported. each key for 'hosts' specifies one rabbitmq broker configuration. if current broker connection fails, module tries to reconnect to another one.
declares exchange
my $exchange = $self->exchange_declare ( 'test.exchange', package => 'My::Exchange', # Net::RabbitMQ::Exchange if omitted passive => 0, # 0 durable => 1, # 1 auto_delete => 0, # 0 exchange_type => "topic" );
declares queue
my $queue = $self->queue_declare ( 'test.queue', package => 'My::Queue', # Net::RabbitMQ::Queue if omitted passive => 0, # 0 durable => 1, # 1 auto_delete => 0, # 0 exclusive => 0 );
publish message to routing key
a typical workflow for a producer role is: open channel, declare exchange, and publish message via routing key
please, note: queue for recieving that message must be declared and binded to exchange using routing key prior to message publishing.
$channel->publish ($publisher_key, $message, {exchange => $exchange->name}, { # content_type => $string, # content_encoding => $string, # correlation_id => $string, # reply_to => $string, # expiration => $string, # message_id => $string, # type => $string, # user_id => $string, app_id => 'test', # delivery_mode => $integer, # priority => $integer, timestamp => time });
stub
Ivan Baktsheev, <apla at the-singlers.us>
<apla at the-singlers.us>
Please report any bugs or feature requests to my email address, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net::RabbitMQ::Channel. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
Copyright 2010-2011 Ivan Baktsheev
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Net::RabbitMQ::Channel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::RabbitMQ::Channel
CPAN shell
perl -MCPAN -e shell install Net::RabbitMQ::Channel
For more information on module installation, please visit the detailed CPAN module installation guide.