-
Notifications
You must be signed in to change notification settings - Fork 0
/
RabbitMqConsumer.php
64 lines (52 loc) · 2.14 KB
/
RabbitMqConsumer.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace LaSalle\Rendimiento\JudithVilela\Shared\Infrastructure\RabbitMq;
use LaSalle\Rendimiento\JudithVilela\ImageRegister\Domain\ImageRegisterRepository;
use LaSalle\Rendimiento\JudithVilela\ImageRegister\Domain\Model\Aggregate\ImageRegister;
use LaSalle\Rendimiento\JudithVilela\ImageRegister\Domain\Model\ValueObject\ImageId;
use LaSalle\Rendimiento\JudithVilela\ImageRegister\Infrastructure\Persistence\Repository\ElasticSearchRepository;
use LaSalle\Rendimiento\JudithVilela\ImageRegister\Infrastructure\Service\ClaviskaImageProcessing;
use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
use PhpAmqpLib\Message\AMQPMessage;
final class RabbitMqConsumer implements ConsumerInterface
{
/** @var ClaviskaImageProcessing */
private $claviskaImage;
/** @var ImageRegisterRepository */
private $imageRegisterRepository;
/** @var ElasticSearchRepository */
private $elasticRepository;
public function __construct(ClaviskaImageProcessing $claviskaImage, ImageRegisterRepository $imageRegisterRepository)
{
$this->claviskaImage = $claviskaImage;
$this->imageRegisterRepository = $imageRegisterRepository;
$this->elasticRepository = new ElasticSearchRepository();
}
/**
* @inheritDoc
*/
public function execute(AMQPMessage $msg)
{
$message = json_decode($msg->body, true);
$this->claviskaImage->processing($message);
$imageRegister = $this->setFormat($message);
$this->imageRegisterRepository->save($imageRegister);
$this->elasticRepository->save($imageRegister);
}
/**
* @param array $parameters
* @return ImageRegister
*/
private function setFormat(array $parameters) :ImageRegister
{
return new ImageRegister(
ImageId::generate(),
$parameters['processedImage'].'.'.$parameters['imageExt'],
$parameters['processedImagePath'],
$parameters['imageExt'],
$parameters['textFilter'],
$parameters['tag'],
$parameters['description'],
''
);
}
}