File: BindsAQueue.pm

package info (click to toggle)
libmessage-passing-amqp-perl 0.008-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 252 kB
  • sloc: perl: 1,688; makefile: 2; sh: 1
file content (74 lines) | stat: -rw-r--r-- 1,551 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package Message::Passing::AMQP::Role::BindsAQueue;
use Moo::Role;
use Types::Standard qw( Str HashRef );
use Scalar::Util qw/ weaken /;
use namespace::autoclean;

with qw/
    Message::Passing::AMQP::Role::DeclaresExchange
    Message::Passing::AMQP::Role::DeclaresQueue
/;

has bind_routing_key => (
    isa => Str,
    is => 'ro',
    default => '#',
);

has bind_arguments => (
    isa => HashRef,
    is => 'ro',
);

after [qw[_set_queue ]] => sub {
    my $self = shift;
    if ($self->_has_exchange && $self->_has_queue) {
        weaken($self);
        $self->_channel->bind_queue(
           queue => $self->queue_name,
           exchange => $self->exchange_name,
           routing_key => $self->bind_routing_key,
           arguments => $self->bind_arguments,
           on_success => sub {
                #warn("Bound queue");
           },
           on_failure => sub {
                warn("Failed to bind queue");
           },
        );
    }
};

1;

=head1 NAME

Message::Passing::AMQP::Role::BindsAQueue

=head1 DESCRIPTION

Role for components which cause a single queue to be bound to a single exchange with a single routing key.

=head1 ATTRIBUTES

=head2 bind_arguments

Gets passed to L<Message::Passing::AMQP::ConnectionManager>, defaults to false.

=head2 bind_routing_key

Defaults to C<#>, which matches any routing key.

=head1 CONSUMES

=over

=item L<Message::Passing::AMQP::Role::BindsQueues>

=item L<Message::Passing::AMQP::Role::DeclaresExchange>

=item L<Message::Passing::AMQP::Role::DeclaresQueue>

=back

=cut