1 | <?php |
||
9 | class OutboxPersister |
||
10 | { |
||
11 | /** |
||
12 | * @var Connection |
||
13 | */ |
||
14 | private $connection; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | private $endpointsTableName; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | * |
||
24 | */ |
||
25 | private $messagesTableName; |
||
26 | |||
27 | /** |
||
28 | * @param Connection $connection |
||
29 | * @param string $messagesTableName |
||
30 | * @param string $endpointsTableName |
||
31 | */ |
||
32 | 15 | public function __construct( |
|
41 | |||
42 | /** |
||
43 | * @param int $endpointId |
||
44 | * @param string $messageId |
||
45 | * |
||
46 | * @return array |
||
47 | * @throws \Throwable |
||
48 | */ |
||
49 | 7 | public function get($endpointId, $messageId) |
|
71 | |||
72 | /** |
||
73 | * @param int $endpointId |
||
74 | * @param array $outboxRecord |
||
75 | * |
||
76 | * @throws \Exception |
||
77 | */ |
||
78 | 6 | public function store($endpointId, array $outboxRecord) |
|
90 | |||
91 | /** |
||
92 | * @param int $endpointId |
||
93 | * @param string $messageId |
||
94 | * |
||
95 | * @throws \Throwable |
||
96 | */ |
||
97 | 4 | public function markAsDispatched($endpointId, $messageId) |
|
114 | |||
115 | /** |
||
116 | * Initiates the transaction |
||
117 | * Attempts to reconnect once if disconnected. |
||
118 | * |
||
119 | * @return void |
||
120 | * @throws \Throwable |
||
121 | */ |
||
122 | 1 | public function beginTransaction() |
|
130 | |||
131 | /** |
||
132 | * Commits the transaction |
||
133 | * |
||
134 | * Does not attempt to reconnect if disconnected because the transaction would be broken anyway. |
||
135 | * Reconnection should be done by rollBack. |
||
136 | * |
||
137 | * @return void |
||
138 | * @throws ConnectionException |
||
139 | */ |
||
140 | public function commit() |
||
144 | |||
145 | /** |
||
146 | * Rolls back the transaction. |
||
147 | * It makes sure that the connection is in the correct state regardless of what happened before. |
||
148 | * Correct state means that connection is not rollback only and does not have a transaction nesting level > 0 |
||
149 | * |
||
150 | * @throws \Throwable |
||
151 | */ |
||
152 | 5 | public function rollBack() |
|
178 | |||
179 | /** |
||
180 | * Attempts to reconnect once if disconnected. |
||
181 | * |
||
182 | * @param \DateTime $dateTime |
||
183 | * |
||
184 | * @throws \Exception |
||
185 | */ |
||
186 | 2 | public function removeEntriesOlderThan(\DateTime $dateTime) |
|
194 | |||
195 | /** |
||
196 | * @param string $endpointName |
||
197 | * |
||
198 | * @return int |
||
199 | * @throws \Exception |
||
200 | */ |
||
201 | 2 | public function fetchOrGenerateEndpointId($endpointName) |
|
226 | |||
227 | /** |
||
228 | * @param string $messageId |
||
229 | * |
||
230 | * @return string |
||
231 | */ |
||
232 | 9 | private function stripDashes($messageId) |
|
236 | |||
237 | /** |
||
238 | * It attempts to reconnect if connection is non responsive. Failing to reconnect triggers a critical error. |
||
239 | * If connection is responsive or successfully reconnected it rethrows, relying on the bus retries |
||
240 | * to re-execute everything from the beginning. |
||
241 | * |
||
242 | * @param \Throwable $t |
||
243 | * |
||
244 | * @return \Throwable|CriticalErrorException |
||
245 | */ |
||
246 | 5 | private function attemptToReconnectPresumedLostConnection(\Throwable $t) |
|
262 | } |
||
263 |