| layout | doc |
|---|---|
| title | AMQP - Codeception - Documentation |
This module interacts with message broker software that implements the Advanced Message Queuing Protocol (AMQP) standard. For example, RabbitMQ (tested). Use it to cleanup the queue between tests.
- Maintainer: davert, tiger-seo
- Stability: alpha
- Contact: codecept@davert.mail.ua
- Contact: tiger.seo@gmail.com
Please review the code of non-stable modules and provide patches if you have issues.
- host: localhost - host to connect
- username: guest - username to connect
- password: guest - password to connect
- vhost: '/' - vhost to connect
- cleanup: true - defined queues will be purged before running every test.
- queues: [mail, twitter] - queues to cleanup
modules:
enabled:
- AMQP:
host: 'localhost'
port: '5672'
username: 'guest'
password: 'guest'
vhost: '/'
queues: [queue1, queue2]
- connection - AMQPStreamConnection - current connection
@since 1.1.2 @author tiger.seo@gmail.com @author davert
Binds a queue to an exchange
This is an alias of method queue_bind of PhpAmqpLib\Channel\AMQPChannel.
{% highlight php %}
bindQueueToExchange( 'nameOfMyQueueToBind', // name of the queue 'transactionTracking.transaction', // exchange name to bind to 'your.routing.key' // Optionally, provide a binding key //.. see the original method for more options ) {% endhighlight %} #### declareExchange Declares an exchange This is an alias of method `exchange_declare` of `PhpAmqpLib\Channel\AMQPChannel`. {% highlight php %} declareExchange( 'nameOfMyExchange', // exchange name 'topic' // exchange type //.. see the original method for more options ) {% endhighlight %} #### declareQueue Declares a queue This is an alias of method `queue_declare` of `PhpAmqpLib\Channel\AMQPChannel`. {% highlight php %} declareQueue( 'nameOfMyQueue', // exchange name //.. see the original method for more options ) {% endhighlight %} #### grabMessageFromQueue Takes last message from queue. $message = $I->grabMessageFromQueue('queue.emails'); * `param` $queue * `return` AMQPMessage #### purgeAllQueues Purge all queues defined in config. {% highlight php %} purgeAllQueues(); ?>{% endhighlight %}
Purge a specific queue defined in config.
{% highlight php %}
purgeQueue('queue.emails'); ?>{% endhighlight %}
Sends message to exchange by sending exchange name, message and (optionally) a routing key
{% highlight php %}
pushToExchange('exchange.emails', 'thanks'); $I->pushToExchange('exchange.emails', new AMQPMessage('Thanks!')); $I->pushToExchange('exchange.emails', new AMQPMessage('Thanks!'), 'severity'); ?>{% endhighlight %}
param$exchangeparam$message string|AMQPMessageparam$routing_key
Sends message to queue
{% highlight php %}
pushToQueue('queue.jobs', 'create user'); $I->pushToQueue('queue.jobs', new AMQPMessage('create')); ?>{% endhighlight %}
param$queueparam$message string|AMQPMessage
Checks if message containing text received.
This method drops message from queue This method will wait for message. If none is sent the script will stuck.
{% highlight php %}
pushToQueue('queue.emails', 'Hello, davert'); $I->seeMessageInQueueContainsText('queue.emails','davert'); ?>{% endhighlight %}
param$queueparam$text