1 | <?php |
||
2 | |||
3 | namespace Kunnu\RabbitMQ; |
||
4 | |||
5 | use Illuminate\Support\Collection; |
||
6 | |||
7 | abstract class RabbitMQMessageConsumer |
||
8 | { |
||
9 | protected Collection $config; |
||
10 | |||
11 | protected ?RabbitMQExchange $exchange = null; |
||
12 | |||
13 | protected ?RabbitMQQueue $queue = null; |
||
14 | |||
15 | public function __construct(array $config = []) |
||
16 | { |
||
17 | $this->setConfig($config); |
||
18 | } |
||
19 | |||
20 | /** |
||
21 | * Handle an incoming message. |
||
22 | * |
||
23 | * @param RabbitMQIncomingMessage $message |
||
24 | * @return void |
||
25 | */ |
||
26 | abstract public function handle(RabbitMQIncomingMessage $message): void; |
||
27 | |||
28 | /** |
||
29 | * Get config. |
||
30 | * |
||
31 | * @return Collection |
||
32 | */ |
||
33 | public function getConfig(): Collection |
||
34 | { |
||
35 | return $this->config; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Set configuration. |
||
40 | * |
||
41 | * @param array $config |
||
42 | * @return self |
||
43 | */ |
||
44 | public function setConfig(array $config): self |
||
45 | { |
||
46 | $this->config = new Collection($config); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
47 | |||
48 | return $this; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return null|\Kunnu\RabbitMQ\RabbitMQExchange|null |
||
53 | */ |
||
54 | public function getExchange(): ?RabbitMQExchange |
||
55 | { |
||
56 | return $this->exchange; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param \Kunnu\RabbitMQ\RabbitMQExchange|null $exchange |
||
61 | * @return self |
||
62 | */ |
||
63 | public function setExchange(?RabbitMQExchange $exchange): self |
||
64 | { |
||
65 | $this->exchange = $exchange; |
||
66 | |||
67 | return $this; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return null|\Kunnu\RabbitMQ\RabbitMQQueue|null |
||
72 | */ |
||
73 | public function getQueue(): ?RabbitMQQueue |
||
74 | { |
||
75 | return $this->queue; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @param \Kunnu\RabbitMQ\RabbitMQQueue|null $queue |
||
80 | * @return self |
||
81 | */ |
||
82 | public function setQueue(?RabbitMQQueue $queue): self |
||
83 | { |
||
84 | $this->queue = $queue; |
||
85 | |||
86 | return $this; |
||
87 | } |
||
88 | } |
||
89 |