Skip to content

Commit 169d47f

Browse files
authored
Wrap consume call in try-finally for context cleanup
Ensure context is destroyed after consuming a package.
1 parent 16c37e1 commit 169d47f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/Process/Consumer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Webman\Stomp\Process;
1616

1717
use support\Container;
18+
use support\Context;
1819
use Workerman\Stomp\Client as StompClient;
1920
use Webman\Stomp\Client;
2021

@@ -67,7 +68,11 @@ public function onWorkerStart()
6768
$headers = $consumer->headers ?? [];
6869
$connection = Client::connection($connection_name);
6970
$cb = function ($client, $package, $ack) use ($consumer) {
70-
\call_user_func([$consumer, 'consume'], $package['body'], $ack, $client);
71+
try {
72+
\call_user_func([$consumer, 'consume'], $package['body'], $ack, $client);
73+
} finally {
74+
Context::destroy();
75+
}
7176
};
7277
$connection->subscribe($queue, $cb, array_merge(['ack' => $ack], $headers));
7378
/*if ($connection->getState() == StompClient::STATE_ESTABLISHED) {

0 commit comments

Comments
 (0)