This repository was archived by the owner on Jul 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbstractConsumer.php
More file actions
83 lines (64 loc) · 1.89 KB
/
AbstractConsumer.php
File metadata and controls
83 lines (64 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
declare(strict_types=1);
namespace Wakeapp\Bundle\RabbitQueueBundle\Consumer;
use Wakeapp\Bundle\RabbitQueueBundle\Exception\HydratorNotFoundException;
use Wakeapp\Bundle\RabbitQueueBundle\Registry\HydratorRegistry;
use PhpAmqpLib\Message\AMQPMessage;
abstract class AbstractConsumer implements ConsumerInterface
{
public const DEFAULT_BATCH_SIZE = 1;
public const DEFAULT_MAX_PROCESSED_TASKS_COUNT = 1000;
private HydratorRegistry $hydratorRegistry;
public function __construct(HydratorRegistry $hydratorRegistry)
{
$this->hydratorRegistry = $hydratorRegistry;
}
private bool $propagationStopped = false;
private int $taskCounter = 0;
public function getBatchSize(): int
{
return static::DEFAULT_BATCH_SIZE;
}
public function isPropagationStopped(): bool
{
return $this->propagationStopped;
}
public function stopPropagation(): void
{
$this->propagationStopped = true;
}
public function incrementProcessedTasksCounter(): void
{
$this->taskCounter++;
}
public function getProcessedTasksCounter(): int
{
return $this->taskCounter;
}
public function getMaxProcessedTasksCount(): int
{
return static::DEFAULT_MAX_PROCESSED_TASKS_COUNT;
}
/**
* @throws HydratorNotFoundException
*/
protected function decodeMessageBody(AMQPMessage $message)
{
$body = $message->getBody();
$contentType = $message->get('content_type');
$hydrator = $this->hydratorRegistry->getHydrator($contentType);
return $hydrator->hydrate($body);
}
/**
* {@inheritDoc}
*/
abstract public function process(array $messageList);
/**
* {@inheritDoc}
*/
abstract public function getBindQueueName(): string;
/**
* {@inheritDoc}
*/
abstract public static function getName(): string;
}