commit | author | age
|
2207d6
|
1 |
# AMQP |
W |
2 |
|
|
3 |
|
|
4 |
This module interacts with message broker software that implements |
|
5 |
the Advanced Message Queuing Protocol (AMQP) standard. For example, RabbitMQ (tested). |
|
6 |
|
|
7 |
<div class="alert alert-info"> |
|
8 |
To use this module with Composer you need <em>"php-amqplib/php-amqplib": "~2.4"</em> package. |
|
9 |
</div> |
|
10 |
|
|
11 |
## Config |
|
12 |
|
|
13 |
* host: localhost - host to connect |
|
14 |
* username: guest - username to connect |
|
15 |
* password: guest - password to connect |
|
16 |
* vhost: '/' - vhost to connect |
|
17 |
* cleanup: true - defined queues will be purged before running every test. |
|
18 |
* queues: [mail, twitter] - queues to cleanup |
|
19 |
* single_channel - create and use only one channel during test execution |
|
20 |
|
|
21 |
### Example |
|
22 |
|
|
23 |
modules: |
|
24 |
enabled: |
|
25 |
- AMQP: |
|
26 |
host: 'localhost' |
|
27 |
port: '5672' |
|
28 |
username: 'guest' |
|
29 |
password: 'guest' |
|
30 |
vhost: '/' |
|
31 |
queues: [queue1, queue2] |
|
32 |
single_channel: false |
|
33 |
|
|
34 |
## Public Properties |
|
35 |
|
|
36 |
* connection - AMQPStreamConnection - current connection |
|
37 |
|
|
38 |
## Actions |
|
39 |
|
|
40 |
### bindQueueToExchange |
|
41 |
|
|
42 |
Binds a queue to an exchange |
|
43 |
|
|
44 |
This is an alias of method `queue_bind` of `PhpAmqpLib\Channel\AMQPChannel`. |
|
45 |
|
|
46 |
```php |
|
47 |
<?php |
|
48 |
$I->bindQueueToExchange( |
|
49 |
'nameOfMyQueueToBind', // name of the queue |
|
50 |
'transactionTracking.transaction', // exchange name to bind to |
|
51 |
'your.routing.key' // Optionally, provide a binding key |
|
52 |
) |
|
53 |
``` |
|
54 |
|
|
55 |
* `param string` $queue |
|
56 |
* `param string` $exchange |
|
57 |
* `param string` $routing_key |
|
58 |
* `param bool` $nowait |
|
59 |
* `param array` $arguments |
|
60 |
* `param int` $ticket |
|
61 |
* `return` mixed|null |
|
62 |
|
|
63 |
### declareExchange |
|
64 |
|
|
65 |
Declares an exchange |
|
66 |
|
|
67 |
This is an alias of method `exchange_declare` of `PhpAmqpLib\Channel\AMQPChannel`. |
|
68 |
|
|
69 |
```php |
|
70 |
<?php |
|
71 |
$I->declareExchange( |
|
72 |
'nameOfMyExchange', // exchange name |
|
73 |
'topic' // exchange type |
|
74 |
) |
|
75 |
``` |
|
76 |
|
|
77 |
* `param string` $exchange |
|
78 |
* `param string` $type |
|
79 |
* `param bool` $passive |
|
80 |
* `param bool` $durable |
|
81 |
* `param bool` $auto_delete |
|
82 |
* `param bool` $internal |
|
83 |
* `param bool` $nowait |
|
84 |
* `param array` $arguments |
|
85 |
* `param int` $ticket |
|
86 |
* `return` mixed|null |
|
87 |
|
|
88 |
|
|
89 |
### declareQueue |
|
90 |
|
|
91 |
Declares queue, creates if needed |
|
92 |
|
|
93 |
This is an alias of method `queue_declare` of `PhpAmqpLib\Channel\AMQPChannel`. |
|
94 |
|
|
95 |
```php |
|
96 |
<?php |
|
97 |
$I->declareQueue( |
|
98 |
'nameOfMyQueue', // exchange name |
|
99 |
) |
|
100 |
``` |
|
101 |
|
|
102 |
* `param string` $queue |
|
103 |
* `param bool` $passive |
|
104 |
* `param bool` $durable |
|
105 |
* `param bool` $exclusive |
|
106 |
* `param bool` $auto_delete |
|
107 |
* `param bool` $nowait |
|
108 |
* `param array` $arguments |
|
109 |
* `param int` $ticket |
|
110 |
* `return` mixed|null |
|
111 |
|
|
112 |
### dontSeeQueueIsEmpty |
|
113 |
|
|
114 |
Checks that queue is not empty. |
|
115 |
|
|
116 |
``` php |
|
117 |
<?php |
|
118 |
$I->pushToQueue('queue.emails', 'Hello, davert'); |
|
119 |
$I->dontSeeQueueIsEmpty('queue.emails'); |
|
120 |
?> |
|
121 |
``` |
|
122 |
|
|
123 |
* `param string` $queue |
|
124 |
|
|
125 |
### grabMessageFromQueue |
|
126 |
|
|
127 |
Takes last message from queue. |
|
128 |
|
|
129 |
``` php |
|
130 |
<?php |
|
131 |
$message = $I->grabMessageFromQueue('queue.emails'); |
|
132 |
?> |
|
133 |
``` |
|
134 |
|
|
135 |
* `param string` $queue |
|
136 |
* `return` \PhpAmqpLib\Message\AMQPMessage |
|
137 |
|
|
138 |
|
|
139 |
### purgeAllQueues |
|
140 |
|
|
141 |
Purge all queues defined in config. |
|
142 |
|
|
143 |
``` php |
|
144 |
<?php |
|
145 |
$I->purgeAllQueues(); |
|
146 |
?> |
|
147 |
``` |
|
148 |
|
|
149 |
|
|
150 |
### purgeQueue |
|
151 |
|
|
152 |
Purge a specific queue defined in config. |
|
153 |
|
|
154 |
``` php |
|
155 |
<?php |
|
156 |
$I->purgeQueue('queue.emails'); |
|
157 |
?> |
|
158 |
``` |
|
159 |
|
|
160 |
* `param string` $queueName |
|
161 |
|
|
162 |
|
|
163 |
### pushToExchange |
|
164 |
|
|
165 |
Sends message to exchange by sending exchange name, message |
|
166 |
and (optionally) a routing key |
|
167 |
|
|
168 |
``` php |
|
169 |
<?php |
|
170 |
$I->pushToExchange('exchange.emails', 'thanks'); |
|
171 |
$I->pushToExchange('exchange.emails', new AMQPMessage('Thanks!')); |
|
172 |
$I->pushToExchange('exchange.emails', new AMQPMessage('Thanks!'), 'severity'); |
|
173 |
?> |
|
174 |
``` |
|
175 |
|
|
176 |
* `param string` $exchange |
|
177 |
* `param string|\PhpAmqpLib\Message\AMQPMessage` $message |
|
178 |
* `param string` $routing_key |
|
179 |
|
|
180 |
|
|
181 |
### pushToQueue |
|
182 |
|
|
183 |
Sends message to queue |
|
184 |
|
|
185 |
``` php |
|
186 |
<?php |
|
187 |
$I->pushToQueue('queue.jobs', 'create user'); |
|
188 |
$I->pushToQueue('queue.jobs', new AMQPMessage('create')); |
|
189 |
?> |
|
190 |
``` |
|
191 |
|
|
192 |
* `param string` $queue |
|
193 |
* `param string|\PhpAmqpLib\Message\AMQPMessage` $message |
|
194 |
|
|
195 |
### seeQueueIsEmpty |
|
196 |
|
|
197 |
Checks that queue is empty |
|
198 |
|
|
199 |
``` php |
|
200 |
<?php |
|
201 |
$I->pushToQueue('queue.emails', 'Hello, davert'); |
|
202 |
$I->purgeQueue('queue.emails'); |
|
203 |
$I->seeQueueIsEmpty('queue.emails'); |
|
204 |
?> |
|
205 |
``` |
|
206 |
|
|
207 |
* `param string` $queue |
|
208 |
|
|
209 |
### seeMessageInQueueContainsText |
|
210 |
|
|
211 |
Checks if message containing text received. |
|
212 |
|
|
213 |
**This method drops message from queue** |
|
214 |
**This method will wait for message. If none is sent the script will stuck**. |
|
215 |
|
|
216 |
``` php |
|
217 |
<?php |
|
218 |
$I->pushToQueue('queue.emails', 'Hello, davert'); |
|
219 |
$I->seeMessageInQueueContainsText('queue.emails','davert'); |
|
220 |
?> |
|
221 |
``` |
|
222 |
|
|
223 |
* `param string` $queue |
|
224 |
* `param string` $text |
|
225 |
|
|
226 |
### seeNumberOfMessagesInQueue |
|
227 |
|
|
228 |
Checks that queue have expected number of messages. |
|
229 |
|
|
230 |
``` php |
|
231 |
<?php |
|
232 |
$I->pushToQueue('queue.emails', 'Hello, davert'); |
|
233 |
$I->seeNumberOfMessagesInQueue('queue.emails',1); |
|
234 |
?> |
|
235 |
``` |
|
236 |
|
|
237 |
* `param string` $queue |
|
238 |
* `param int` $expected |
|
239 |
|
|
240 |
<p> </p><div class="alert alert-warning">Module reference is taken from the source code. <a href="https://github.com/Codeception/Codeception/tree/2.5/src/Codeception/Module/AMQP.php">Help us to improve documentation. Edit module reference</a></div> |