Completed
Push — master ( 53783e...ee648a )
by Olivier
22s queued 20s
created

examples/04-stomp-consumer.php (3 issues)

1
<?php
2
/**
3
 * See http://www.rabbitmq.com/stomp.html for more infos.
4
 * Run with rabbit stomp plugin.
5
 *
6
 * You must enable the plugin
7
 *   `rabbitmq-plugins enable rabbitmq_stomp`
8
 * You need to create rabbit user (stompUser, stompPass)
9
 *   Guest user have security restriction. See https://github.com/stomp-php/stomp-php/issues/105
10
 *
11
 * This example is the consumer part.
12
 * It print the message body
13
 * if the message body is "wrong" the message will be nack
14
 * else ack all message
15
 */
16
require_once __DIR__.'/../vendor/autoload.php';
17
18
use Swarrot\Broker\Message;
19
use Swarrot\Broker\MessageProvider\StatefulStompMessageProvider;
0 ignored issues
show
The type Swarrot\Broker\MessagePr...fulStompMessageProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Swarrot\Consumer;
21
use Swarrot\Processor\Callback\CallbackProcessor;
22
23
$client = new \Stomp\Client('tcp://localhost:61613');
0 ignored issues
show
The type Stomp\Client was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
$client->setLogin('stompUser', 'stompPass');
25
$client->setVhostname('/');
26
$client->connect();
27
28
$stompMessageProvider = new StatefulStompMessageProvider($client, '/queue/stomp_queue');
29
30
$processor = new CallbackProcessor(function (Message $message, array $options) use ($stompMessageProvider) {
0 ignored issues
show
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
$processor = new CallbackProcessor(function (Message $message, /** @scrutinizer ignore-unused */ array $options) use ($stompMessageProvider) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    $body = $message->getBody();
32
    if ('wrong' == $body) {
33
        echo "$body NACK\r\n";
34
        $stompMessageProvider->nack($message);
35
36
        return;
37
    }
38
    echo "$body\r\n";
39
    $stompMessageProvider->ack($message);
40
});
41
42
$consumer = new Consumer($stompMessageProvider, $processor);
43
44
$consumer->consume([]);
45