Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
producer.php
1<?php
2
4
14
16{
17 private ?MessageMapper $mapper = null;
18
28 public function send(Interfaces\Message $message): void
29 {
30 $this->getMapper()->create($message);
31 $this->throwEventForQueue($message);
32 }
33
42 public function sendBatch(array $messages): void
43 {
44 $dateCreate = new DateTime();
45 $realMessagesData = [];
46
47 foreach ($messages as $message)
48 {
49 if ($message instanceof Interfaces\Message)
50 {
51 $realMessagesData[] = [
52 'MESSAGE' => [
53 Dictionary::MESSAGE_PARTS['body'] => $message->getBody(),
54 Dictionary::MESSAGE_PARTS['headers'] => $message->getHeaders(),
55 Dictionary::MESSAGE_PARTS['properties'] => $message->getProperties(),
56 ],
57 'DATE_CREATE' => $dateCreate,
58 ];
59 }
60 }
61
62 if (!empty($realMessagesData))
63 {
64 QueueMessageTable::addMulti($realMessagesData, true);
65 $this->throwEventForQueue();
66 }
67 }
68
72 private function getMapper(): ?MessageMapper
73 {
74 if ($this->mapper === null)
75 {
76 $this->mapper = new MessageMapper();
77 }
78
79 return $this->mapper;
80 }
81
88 private function throwEventForQueue(Interfaces\Message $message = null): void
89 {
90 // it's one of ways. We can use agent for delayed start of RuleMaster
91 (new RuleMaster())->run();
92 }
93}
send(Interfaces\Message $message)
Definition producer.php:28