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

examples/01-consumer-with-stacked-processor.php (3 issues)

1
<?php
2
3
require_once __DIR__.'/../vendor/autoload.php';
4
5
use Swarrot\Broker\Message;
6
use Swarrot\Broker\PeclPackageMessageProvider;
0 ignored issues
show
The type Swarrot\Broker\PeclPackageMessageProvider 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...
7
use Swarrot\Consumer;
8
use Swarrot\Processor\ProcessorInterface;
9
10
class Processor implements ProcessorInterface
11
{
12
    protected $processor;
13
14
    protected $num;
15
16
    public function __construct($processor, $num = 1)
17
    {
18
        $this->processor = $processor;
19
        $this->num = (int) $num;
20
    }
21
22
    public function process(Message $message, array $options)
23
    {
24
        printf("Start processing message #%d in processor #%d\n", $message->getId(), $this->num);
0 ignored issues
show
Bug Best Practice introduced by
The property num does not exist on Processor. Did you maybe forget to declare it?
Loading history...
25
        $return = $this->processor->process($message, $options);
0 ignored issues
show
Bug Best Practice introduced by
The property processor does not exist on Processor. Did you maybe forget to declare it?
Loading history...
26
        printf("End processing message #%d in processor #%d\n", $message->getId(), $this->num);
27
28
        return $return;
29
    }
30
}
31
32
class FinalProcessor implements ProcessorInterface
33
{
34
    public function process(Message $message, array $options)
35
    {
36
        printf("Consume message #%d\n", $message->getId());
37
    }
38
}
39
40
$connection = new \AMQPConnection();
41
$connection->connect();
42
$channel = new \AMQPChannel($connection);
43
$queue = new \AMQPQueue($channel);
44
$queue->setName('global');
45
46
$messageProvider = new PeclPackageMessageProvider($queue);
47
48
$stack = (new \Swarrot\Processor\Stack\Builder())
49
    ->push('Processor', 1)
50
    ->push('Processor', 2)
51
;
52
$processor = $stack->resolve(new FinalProcessor());
53
54
$consumer = new Consumer($messageProvider, $processor);
55
$consumer->consume();
56