Completed
Push — master ( 11b317...37df4d )
by Lucas
09:27
created

DumpConsumer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 31
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 0 20 5
1
<?php
2
3
/**
4
 * Consumes RabbitMQ messages and dumps them.
5
 */
6
7
namespace Graviton\RabbitMqBundle\Service;
8
9
use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
10
use PhpAmqpLib\Message\AMQPMessage;
11
12
/**
13
 * Consumes RabbitMQ messages and dumps them.
14
 *
15
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
16
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
17
 * @link     http://swisscom.ch
18
 */
19
class DumpConsumer implements ConsumerInterface
20
{
21
22
    /**
23
     * Callback executed when a message is received. Dumps the message body, delivery_info and properties.
24
     *
25
     * @param AMQPMessage $msg The received message.
26
     *
27
     * @return void
28
     */
29
    public function execute(AMQPMessage $msg)
30
    {
31
        echo str_repeat('-', 60).PHP_EOL;
32
33
        echo '[RECV ' . date('c') . ']' . PHP_EOL .'<content>' .
34
            PHP_EOL . $msg->body . PHP_EOL . '</content>'.PHP_EOL.PHP_EOL;
35
36
        echo "*" . ' INFO ' . PHP_EOL;
37
        foreach ($msg->{'delivery_info'} as $key => $value) {
38
            if (is_scalar($value)) {
39
                echo "** " . $key . ' = ' . $value . PHP_EOL;
40
            }
41
        }
42
        echo "*" . ' PROPERTIES ' . PHP_EOL;
43
        foreach ($msg->get_properties() as $property => $value) {
44
            if (is_scalar($value)) {
45
                echo "** " . $property . ' = ' . $value . PHP_EOL;
46
            }
47
        }
48
    }
49
}
50