-
Notifications
You must be signed in to change notification settings - Fork 439
/
Copy pathconsume.php
42 lines (32 loc) · 890 Bytes
/
consume.php
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
37
38
39
40
41
42
<?php
$autoload = null;
foreach ([__DIR__.'/../vendor/autoload.php', __DIR__.'/../../../vendor/autoload.php'] as $file) {
if (file_exists($file)) {
$autoload = $file;
break;
}
}
if ($autoload) {
require_once $autoload;
} else {
throw new LogicException('Composer autoload was not found');
}
use Enqueue\Dbal\DbalConnectionFactory;
$config = [
'connection' => [
'url' => getenv('DOCTRINE_DSN'),
'driver' => 'pdo_mysql',
],
];
$factory = new DbalConnectionFactory($config);
$context = $factory->createContext();
$context->createDataBaseTable();
$destination = $context->createTopic('destination');
$consumer = $context->createConsumer($destination);
while (true) {
if ($m = $consumer->receive(1000)) {
$consumer->acknowledge($m);
echo 'Received message: '.$m->getBody().\PHP_EOL;
}
}
echo 'Done'."\n";