This repository has been archived by the owner on Jul 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
RabbitMqProducer.php
49 lines (40 loc) · 1.73 KB
/
RabbitMqProducer.php
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
<?php
declare(strict_types=1);
namespace Wakeapp\Bundle\RabbitQueueBundle\Producer;
use Wakeapp\Bundle\RabbitQueueBundle\Exception\DefinitionNotFoundException;
use Wakeapp\Bundle\RabbitQueueBundle\Exception\HydratorNotFoundException;
use Wakeapp\Bundle\RabbitQueueBundle\Exception\RabbitQueueException;
use Wakeapp\Bundle\RabbitQueueBundle\Registry\DefinitionRegistry;
use Wakeapp\Bundle\RabbitQueueBundle\Registry\HydratorRegistry;
use Wakeapp\Bundle\RabbitQueueBundle\Registry\PublisherRegistry;
class RabbitMqProducer implements RabbitMqProducerInterface
{
private DefinitionRegistry $definitionRegistry;
private HydratorRegistry $hydratorRegistry;
private PublisherRegistry $publisherRegistry;
private string $hydratorName;
public function __construct(
DefinitionRegistry $definitionRegistry,
HydratorRegistry $hydratorRegistry,
PublisherRegistry $publisherRegistry,
string $hydratorName
) {
$this->definitionRegistry = $definitionRegistry;
$this->hydratorRegistry = $hydratorRegistry;
$this->hydratorName = $hydratorName;
$this->publisherRegistry = $publisherRegistry;
}
/**
* @throws RabbitQueueException
* @throws DefinitionNotFoundException
* @throws HydratorNotFoundException
*/
public function put(string $queueName, $data, array $options = []): void
{
$dataString = $this->hydratorRegistry->getHydrator($this->hydratorName)->dehydrate($data);
$definition = $this->definitionRegistry->getDefinition($queueName);
$queueType = $definition->getQueueType();
$publisher = $this->publisherRegistry->getPublisher($queueType);
$publisher->publish($definition, $dataString, $options);
}
}