AMQP

 view release on metacpan or  search on metacpan

lib/AMQP.pm  view on Meta::CPAN

package AMQP;
our $VERSION = '0.01';

use Mojo::Base -base;

sub server {
	my ($self,$url) = @_;
	$url ||= '';			# incase we don't pass a url
	$url =~ /amqp:\/\/
		(?<username>[^:]+):
		(?<password>[^@]+)@
		(?<hostname>[^:\/]+):
		(?<port>\d+)\/
		(?<vhost>[^\/]*)
	/x;
	$self->host($+{'hostname'} || 'localhost');
	$self->port($+{'port'} || 5672);
	$self->vhost($+{'vhost'} || '/');
	$self->username($+{'username'} || 'guest');
	$self->password($+{'password'} || 'guest');
	say "amqp://" . $self->host . ":" . $self->port . $self->vhost if $self->debug;
	$self;
}

1;

__DATA__

=pod

lib/AMQP.pm  view on Meta::CPAN

=head1 DESCRIPTION

The AMQP class provides the basic functionality common to all AMQP utility classes.

=head1 METHODS

B<server($url)>

Configures all of the connection settings based on an AMQP url.  The format of which is:
  
 amqp://username:password@host:port/vhost

All of the elements of the url are required if you are not using the defaults.  The default settings are:

 amqp://guest:guest@localhost:5672/

=head1 TODO

=head1 BUGS

=head1 COPYRIGHT

lib/AMQP/Publisher.pm  view on Meta::CPAN

our $VERSION = '0.01';

use Mojo::Base 'AMQP';
use AnyEvent::RabbitMQ;
use Sys::Hostname;

has 'debug' => 1;
has 'host' => 'localhost';
has 'port' => 5672;
has 'user' => 'guest';
has 'password' => 'guest';
has 'vhost' => '/';
has 'timeout' => 1;
has 'heartbeat' => 30;
has 'exchange' => 'log';
has 'type' => 'topic';
has 'key' => '#';
has 'rabbit';
has 'connection';
has 'channel';
has 'status';

lib/AMQP/Publisher.pm  view on Meta::CPAN


sub attach {
	my $self = shift;
	$self->status(AnyEvent->condvar);
	$self->rabbit(AnyEvent::RabbitMQ->new);
	$self->rabbit->load_xml_spec();
	$self->rabbit->connect(
		host => $self->host,
		port => $self->port,
		user => $self->user,
		pass => $self->password,
		vhost => $self->vhost,
		timeout => $self->timeout,
		tune => { heartbeat => $self->heartbeat },
		on_success => sub {
			say "Connected to amqp://" . $self->host . ":" . $self->port . $self->vhost if $self->debug;
			$self->connection(shift);
			$self->connection->open_channel(
				on_failure => $self->status,
				on_close => sub {
					say "Channel closed" if $self->debug;

lib/AMQP/Publisher.pm  view on Meta::CPAN

B<new()> (constructor)

Creates a new AMQP::Producer which can 

Returns: new instance of this class.

B<server($url)>

Configures all of the connection settings based on an AMQP url.  The format of which is:
  
 amqp://username:password@host:port/vhost

All of the elements of the url are required if you are not using the defaults.  The default settings are:

 amqp://guest:guest@localhost:5672/

B<attach()>

Connects to the AMQP server specified by the C<server()> method.  When the server connects it will invoke the publisher's C<on_connect()>
callback.  This can enable you to setup additional event loops to drive the publisher.

lib/AMQP/Subscriber.pm  view on Meta::CPAN

our $VERSION = '0.01';

use Mojo::Base 'AMQP';
use AnyEvent::RabbitMQ;
use Sys::Hostname;

has 'debug' => 1;
has 'host' => 'localhost';
has 'port' => 5672;
has 'username' => 'guest';
has 'password' => 'guest';
has 'vhost' => '/';
has 'timeout' => 1;
has 'heartbeat' => 30;
has 'exchange' => 'test';
has 'type' => 'topic';
has 'key' => '#';
has 'queue' => 'test';
has 'rabbit';
has 'connection';
has 'channel';

lib/AMQP/Subscriber.pm  view on Meta::CPAN

sub attach {
	my $self = shift;
	$self->useragent(Mojo::UserAgent->new);
	$self->status(AnyEvent->condvar);
	$self->rabbit(AnyEvent::RabbitMQ->new);
	$self->rabbit->load_xml_spec();
	$self->rabbit->connect(
		host => $self->host,
		port => $self->port,
		username => $self->username,
		pass => $self->password,
		vhost => $self->vhost,
		timeout => $self->timeout,
		tune => { heartbeat => $self->heartbeat },
		on_success => sub {
			say "Connected to amqp://" . $self->host . ":" . $self->port . $self->vhost if $self->debug;
			$self->connection(shift);
			$self->connection->open_channel(
				on_failure => $self->status,
				on_close => sub {
					say "Channel closed" if $self->debug;

lib/AMQP/Subscriber.pm  view on Meta::CPAN


Create a new instance of this class. Initialize the object with
whatever is in C<\%params>, which are not predefined.</p>

Returns: new instance of this class.

B<server($url)>

Configures all of the connection settings based on an AMQP url.  The format of which is:
  
 amqp://username:password@host:port/vhost

All of the elements of the url are required if you are not using the defaults.  The default settings are:

 amqp://guest:guest@localhost:5672/

B<attach()>
 

=head1 TODO

t/subscriber.t  view on Meta::CPAN

my $s = AMQP::Subscriber->new;

isa_ok($s,'AMQP::Subscriber');

# Test overriding the defaults
$s->server('amqp://foo:bar@test:25672/test');
is($s->host, 'test', 'host set');
is($s->port, 25672, 'port set');
is($s->vhost, 'test', 'vhost set');
is($s->username, 'foo', 'user set');
is($s->password, 'bar', 'password set');

# Test the defaults
$s->server();
is($s->host, 'localhost', 'localhost default');
is($s->port, 5672, 'port default');
is($s->vhost, '/', 'vhost default');
is($s->username, 'guest', 'user default');
is($s->password, 'guest', 'password default');


done_testing();



( run in 0.679 second using v1.01-cache-2.11-cpan-49f99fa48dc )