• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/Test/Net/H22-Apr-2015-660308

t/H22-Apr-2015-881635

ChangesH A D22-Apr-20151.9 KiB7843

INSTALLH A D22-Apr-2015992 4424

LICENSEH A D22-Apr-201517.9 KiB380292

MANIFESTH A D22-Apr-2015578 3635

META.jsonH A D22-Apr-201523.7 KiB736734

META.ymlH A D22-Apr-201515.1 KiB539538

Makefile.PLH A D22-Apr-20151.4 KiB6554

README.mdH A D22-Apr-20155.3 KiB193117

cpanfileH A D22-Apr-2015952 3732

dist.iniH A D22-Apr-2015303 1412

weaver.iniH A D22-Apr-2015246 2315

README.md

1NAME
2
3    Test::Net::RabbitMQ - A mock RabbitMQ implementation for use when
4    testing.
5
6VERSION
7
8    version 0.13
9
10SYNOPSIS
11
12        use Test::Net::RabbitMQ;
13
14        my $mq = Test::Net::RabbitMQ->new;
15
16        $mq->connect;
17
18        $mq->channel_open(1);
19
20        $mq->exchange_declare(1, 'order');
21        $mq->queue_declare(1, 'new-orders');
22
23        $mq->queue_bind(1, 'new-orders', 'order', 'order.new');
24
25        $mq->publish(1, 'order.new', 'hello!', { exchange => 'order' });
26
27        $mq->consume(1, 'new-orders');
28
29        my $msg = $mq->recv;
30
31        # Or
32
33        my $msg = $mq->get(1, 'order.new', {});
34
35DESCRIPTION
36
37    Test::Net::RabbitMQ is a terrible approximation of using the real
38    thing, but hopefully will allow you to test systems that use
39    Net::AMQP::RabbitMQ or Net::RabbitMQ without having to use an actual
40    RabbitMQ instance.
41
42    The general overview is that calls to publish pushes a message into one
43    or more queues (or none if there are no bindings) and calls to recv pop
44    them.
45
46CAVEATS
47
48    This module has all the features I've needed to successfully test our
49    RabbitMQ-using application. Patches are welcome if I'm missing
50    something you need! At the moment there are a number of shortcomings:
51
52    recv doesn't block
53
54    exchanges are all topic
55
56    lots of other stuff!
57
58ATTRIBUTES
59
60 connectable
61
62    If false then any calls to connect will die to emulate a failed
63    connection.
64
65 debug
66
67    If set to true (which you can do at any time) then a message will be
68    emitted to STDERR any time a message is added to a queue.
69
70METHODS
71
72 channel_close($number)
73
74    Closes the specific channel.
75
76 channel_open($number)
77
78    Opens a channel with the specific number.
79
80 connect
81
82    Connects this instance. Does nothing except set connected to true. Will
83    throw an exception if you've set connectable to false.
84
85 consume($channel, $queue)
86
87    Sets the queue that will be popped when recv is called.
88
89 cancel($channel, $consumer_tag)
90
91    Cancels the subscription for the given consumer tag. Calls to recv
92    after this will throw an error unless you call consume again. This
93    method always returns true if there is a subscription to cancel, false
94    otherwise.
95
96 disconnect
97
98    Disconnects this instance by setting connected to false.
99
100 exchange_declare($channel, $exchange, $options)
101
102    Creates an exchange of the specified name.
103
104 exchange_delete($channel, $exchange, $options)
105
106    Deletes an exchange of the specified name.
107
108 tx_select($channel)
109
110    Begins a transaction on the specified channel. From this point forward
111    all publish() calls on the channel will be buffered until a call to
112    "tx_commit" or "tx_rollback" is made.
113
114 tx_commit($channel)
115
116    Commits a transaction on the specified channel, causing all buffered
117    publish() calls to this point to be published.
118
119 tx_rollback($channel)
120
121    Rolls the transaction back, causing all buffered publish() calls to be
122    wiped.
123
124 get ($channel, $queue, $options)
125
126    Get a message from the queue, if there is one.
127
128    Like Net::RabbitMQ, this will return a hash containing the following
129    information:
130
131         {
132           body => 'Magic Transient Payload', # the reconstructed body
133           routing_key => 'nr_test_q',        # route the message took
134           exchange => 'nr_test_x',           # exchange used
135           delivery_tag => uint64(1),         # (inc'd every recv or get)
136           redelivered => 0,                  # always 0
137           message_count => 0,                # always 0
138         }
139
140 queue_bind($channel, $queue, $exchange, $routing_key)
141
142    Binds the specified queue to the specified exchange using the provided
143    routing key. Note that, at the moment, this doesn't work with AMQP
144    wildcards. Only with exact matches of the routing key.
145
146 queue_declare($channel, $queue, $options)
147
148    Creates a queue of the specified name.
149
150 queue_delete($channel, $queue, $options)
151
152    Deletes a queue of the specified name.
153
154 queue_unbind($channel, $queue, $exchange, $routing_key)
155
156    Unbinds the specified routing key from the provided queue and exchange.
157
158 publish($channel, $routing_key, $body, $options)
159
160    Publishes the specified body with the supplied routing key. If there is
161    a binding that matches then the message will be added to the
162    appropriate queue(s).
163
164 recv
165
166    Provided you've called consume then calls to recv will pop the next
167    message of the queue. Note that this method does not block.
168
169    Like Net::RabbitMQ, this will return a hash containing the following
170    information:
171
172         {
173           body => 'Magic Transient Payload', # the reconstructed body
174           routing_key => 'nr_test_q',        # route the message took
175           exchange => 'nr_test_x',           # exchange used
176           delivery_tag => uint64(1),         # (inc'd every recv or get)
177           redelivered => $boolean            # if message is redelivered
178           consumer_tag => '',                # Always blank currently
179           props => $props,                   # hashref sent in
180         }
181
182AUTHOR
183
184    Cory G Watson <gphat@cpan.org>
185
186COPYRIGHT AND LICENSE
187
188    This software is copyright (c) 2015 by Cory G Watson.
189
190    This is free software; you can redistribute it and/or modify it under
191    the same terms as the Perl 5 programming language system itself.
192
193