-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskApp.php
More file actions
52 lines (47 loc) · 1.76 KB
/
TaskApp.php
File metadata and controls
52 lines (47 loc) · 1.76 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
<?php
namespace Samples\TaskService;
use Micronative\EventSchema\Processor;
use Micronative\MockBroker\Broker;
use Micronative\MockBroker\Consumer;
use Micronative\MockBroker\ConsumerInterface;
use Psr\Container\ContainerInterface;
use Samples\TaskService\Events\TaskEvent;
class TaskApp
{
const USER_EVENT_TOPIC = 'User.Events';
private ConsumerInterface $consumer;
private Processor $processor;
/**
* App constructor.
* @param \Micronative\MockBroker\Broker|null $broker
* @param \Psr\Container\ContainerInterface|null $container
* @throws \Micronative\EventSchema\Exceptions\ConfigException
* @throws \Micronative\EventSchema\Exceptions\JsonException
*/
public function __construct(Broker $broker = null, ContainerInterface $container = null)
{
$this->consumer = new Consumer($broker);
$this->processor = new Processor(
dirname(__FILE__),
["/assets/configs/in_events.yml"],
["/assets/configs/services.yml"],
$container
);
}
/**
* @throws \Micronative\EventSchema\Exceptions\ProcessorException
* @throws \Micronative\EventSchema\Exceptions\JsonException
* @throws \Micronative\EventSchema\Exceptions\ServiceException
* @throws \Micronative\EventSchema\Exceptions\ValidatorException
*/
public function listen()
{
$message = $this->consumer->consume(self::USER_EVENT_TOPIC);
if (!empty($message)) {
$taskEvent = (new TaskEvent())->fromJson($message);
echo "-- Start processing incoming event: {$taskEvent->getName()}" . PHP_EOL;
$this->processor->process($taskEvent);
echo "-- Finish processing incoming event: {$taskEvent->getName()}" . PHP_EOL;
}
}
}