File Coverage

blib/lib/Crixa/Channel.pm
Criterion Covered Total %
statement 26 30 86.6
branch 1 4 25.0
condition n/a
subroutine 9 11 81.8
pod 4 5 80.0
total 40 50 80.0


line stmt bran cond sub pod time code
1             package Crixa::Channel;
2              
3 1     1   4 use strict;
  1         2  
  1         31  
4 1     1   3 use warnings;
  1         1  
  1         23  
5 1     1   4 use namespace::autoclean;
  1         1  
  1         6  
6              
7             our $VERSION = '0.12';
8              
9 1     1   63 use Moose;
  1         2  
  1         4  
10              
11 1     1   4673 use Crixa::Queue;
  1         3  
  1         39  
12 1     1   524 use Crixa::Exchange;
  1         4  
  1         247  
13              
14             with qw(Crixa::HasMQ);
15              
16             has id => ( isa => 'Str', is => 'ro', required => 1 );
17              
18 9     9 0 199 sub BUILD { $_[0]->_mq->channel_open( $_[0]->id ); }
19              
20             sub exchange {
21 8     8 1 119 my $self = shift;
22 8         154 Crixa::Exchange->new(
23             @_,
24             channel => $self,
25             _mq => $self->_mq,
26             );
27             }
28              
29             sub basic_qos {
30 0     0 1 0 my $self = shift;
31 0 0       0 my $args = @_ == 1 ? $_[0] : {@_};
32 0         0 $self->_mq->basic_qos( $self->id, $args );
33             }
34              
35             sub queue {
36 8     8 1 10 my $self = shift;
37 8 50       44 my $args = @_ == 1 ? shift : {@_};
38 8         154 $args->{_mq} = $self->_mq;
39 8         18 $args->{channel} = $self;
40 8         168 return Crixa::Queue->new($args);
41             }
42              
43 0     0 1   sub ack { $_[0]->_mq->ack( shift->id, @_ ) }
44              
45             __PACKAGE__->meta->make_immutable;
46              
47             1;
48              
49             # ABSTRACT: A Crixa Channel
50              
51             __END__
52              
53             =pod
54              
55             =head1 NAME
56              
57             Crixa::Channel - A Crixa Channel
58              
59             =head1 VERSION
60              
61             version 0.12
62              
63             =head1 DESCRIPTION
64              
65             This class represents a channel. A channel is a lot like a socket. You will
66             probably want to have a unique channel per process or thread for your
67             application. You may also want to have separate channels for publishing and
68             consuming messages.
69              
70             It is safe (and encouraged) to keep the same channel open over a long period
71             of time for publishing or consuming messages. There is no need to create new
72             channels on a regular basis.
73              
74             Also note that message delivery tags are scoped to the channel on which a
75             message is delivered, and therefore message acks must go back to that same
76             channel.
77              
78             Channels are created by calling the C<< Crixa->new_channel >> method.
79              
80             =encoding UTF-8
81              
82             =head1 METHODS
83              
84             This class provides the following methods:
85              
86             =head2 $channel->exchange(...)
87              
88             This method creates a new L<Crixa::Exchange> object. Any parameters passed to
89             this method are passed directly to the L<Crixa::Exchange> constructor, either
90             as a hash or hashref. See the L<Crixa::Exchange> documentation for more
91             details.
92              
93             =head2 $channel->queue(...)
94              
95             This method creates a new L<Crixa::Queue> object. Any parameters passed to
96             this method are passed directly to the L<Crixa::Queue> constructor, either as
97             a hash or hashref. See the L<Crixa::Queue> documentation for more details.
98              
99             =head2 $channel->basic_qos(...)
100              
101             This method sets quality of service flags for the channel. This method
102             takes a hash or hash reference with the following keys:
103              
104             =over 4
105              
106             =item * prefetch_count => $count
107              
108             If this is set, then the channel will fetch C<$count> additional messages to
109             the client when it is consuming messages, rather than sending them down the
110             socket one at a time.
111              
112             =item * prefetch_size => $size
113              
114             Set the maximum number of I<bytes> that will be prefetched. If both this and
115             C<prefetch_count> are set then the smaller of the two wins.
116              
117             =item * global => $bool
118              
119             If this is true, then the QoS settings apply to all consumers on this
120             channel. If it is false, then it only applies to new consumers created after
121             this is set.
122              
123             In Crixa, a new AMQP consumer is created whenever you call any methods to get
124             messages on a L<Crixa::Queue> object, so this setting doesn't really matter.
125              
126             =back
127              
128             Note that prefetching messages is only done when the queue is created in "no
129             ack" mode (or "auto ack" if you prefer to think of it that way).
130              
131             =head2 $channel->ack(...)
132              
133             This method acknowledges delivery of a message received on this channel.
134              
135             It accepts two positional arguments. The first is the delivery tag for the
136             message, which is required. The second is the "multiple" flag. If this is
137             true, it means that you are acknowledging all messages up to the given
138             delivery tag. It defaults to false.
139              
140             =head2 $channel->id
141              
142             This returns the channel's unique id. This is a positive integer.
143              
144             =head2 Crixa::Channel->new(...)
145              
146             Don't call this method directly. Instead, call C<new_channel> on a connected
147             L<Crixa> object.
148              
149             =head1 AUTHORS
150              
151             =over 4
152              
153             =item *
154              
155             Chris Prather <chris@prather.org>
156              
157             =item *
158              
159             Dave Rolsky <autarch@urth.org>
160              
161             =back
162              
163             =head1 COPYRIGHT AND LICENSE
164              
165             This software is copyright (c) 2012 - 2015 by Chris Prather.
166              
167             This is free software; you can redistribute it and/or modify it under
168             the same terms as the Perl 5 programming language system itself.
169              
170             =cut