-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconsume.php
More file actions
36 lines (21 loc) · 751 Bytes
/
consume.php
File metadata and controls
36 lines (21 loc) · 751 Bytes
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
<?php
declare(strict_types=1);
include __DIR__ . '/../vendor/autoload.php';
$connection = \Doctrine\DBAL\DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'path' => '/db/queue.db',
]);
$transport = new \Simple\Queue\Transport\DoctrineDbalTransport($connection);
$producer = new \Simple\Queue\Producer($transport);
$consumer = new \Simple\Queue\Consumer($transport, $producer);
// create table for queue messages
$transport->init();
echo 'Start consuming' . PHP_EOL;
while (true) {
if ($message = $transport->fetchMessage(['my_queue'])) {
// Your message handling logic
$consumer->acknowledge($message);
echo sprintf('Received message: %s ', $message->getBody());
echo PHP_EOL;
}
}