Lines
n/a
0 / 0
Functions and Methods
n/a
0 / 0
Classes and Traits
n/a
0 / 0
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Tomaj\Hermes\Driver; | |
| 6 | ||
| 7 | use Closure; | |
| 8 | use Tomaj\Hermes\Dispatcher; | |
| 9 | use Tomaj\Hermes\MessageInterface; | |
| 10 | use Tomaj\Hermes\SerializeException; | |
| 11 | use Tomaj\Hermes\Shutdown\ShutdownException; | |
| 12 | ||
| 13 | interface DriverInterface | |
| 14 | { | |
| 15 | /** | |
| 16 | * Send message | |
| 17 | * | |
| 18 | * In this method you have to implement logic to insert messages to process in queue. | |
| 19 | * This method has to be as fast as possible because it will be called in | |
| 20 | * web server threads. | |
| 21 | * | |
| 22 | * @throws SerializeException | |
| 23 | * @throws UnknownPriorityException | |
| 24 | */ | |
| 25 | public function send(MessageInterface $message, int $priority = Dispatcher::DEFAULT_PRIORITY): bool; | |
| 26 | ||
| 27 | /** | |
| 28 | * Setup new queue with priority. | |
| 29 | * Each message can be directed to specific queue. | |
| 30 | * In general you messages will be processed based on queue (higher priority will be processed first) | |
| 31 | * Or you can define dispatcher that will handle only specific priority (queue)s | |
| 32 | * | |
| 33 | * @param int $priority higher priority will be processed first | |
| 34 | * @throws NotSupportedException | |
| 35 | */ | |
| 36 | public function setupPriorityQueue(string $name, int $priority): void; | |
| 37 | ||
| 38 | /** | |
| 39 | * Processing wait method. | |
| 40 | * | |
| 41 | * Dispatcher will call this method for receiving data from driver. | |
| 42 | * This can be implemented as infinite loop and checking driver in periodic time for new messages | |
| 43 | * or can be implemented as callback for driver emit method (like rabbitmq or redis pubsub). | |
| 44 | * When driver receive new message, you have to call $callback with this message like $callback($message) | |
| 45 | * | |
| 46 | * @param int[] $priorities | |
| 47 | * | |
| 48 | * @throws UnknownPriorityException | |
| 49 | * @throws ShutdownException | |
| 50 | */ | |
| 51 | public function wait(Closure $callback, array $priorities): void; | |
| 52 | } |