-
Notifications
You must be signed in to change notification settings - Fork 0
/
DumpAsyncCallback.php
49 lines (43 loc) · 1.33 KB
/
DumpAsyncCallback.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
43
44
45
46
47
48
49
<?php declare(strict_types=1);
namespace RabbitMqBundle\Consumer\Callback;
use Exception;
use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Promise\PromiseInterface;
use PhpAmqpLib\Message\AMQPMessage;
use RabbitMqBundle\Connection\Connection;
use RabbitMqBundle\Consumer\AsyncCallbackInterface;
use RabbitMqBundle\Utils\Message;
/**
* Class DumpAsyncCallback
*
* @package RabbitMqBundle\Consumer\Callback
*/
final class DumpAsyncCallback implements AsyncCallbackInterface
{
/**
* @param AMQPMessage $message
* @param Connection $connection
* @param int $channelId
*
* @return PromiseInterface
* @throws Exception
*/
public function processMessage(AMQPMessage $message, Connection $connection, int $channelId): PromiseInterface
{
var_dump(['body' => Message::getBody($message), 'headers' => Message::getHeaders($message)]);
$promise = new Promise(
static function () use (&$promise): void {
if ($promise) {
$promise->resolve('waited');
}
},
);
$promise
->then(
static function () use (&$message, $connection, $channelId): void {
Message::ack($message, $connection, $channelId);
}
);
return $promise;
}
}