Skip to content

Commit 9916eb3

Browse files
committed
#83277
1 parent 90d795f commit 9916eb3

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/RdKafkaConsumerMiddleware.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Ensi\LaravelInitialEventPropagation;
4+
5+
use Closure;
6+
use Ensi\InitialEventPropagation\Config;
7+
use Ensi\InitialEventPropagation\InitialEventDTO;
8+
use Ensi\InitialEventPropagation\InitialEventHolder;
9+
use RdKafka\Message;
10+
11+
class RdKafkaConsumerMiddleware
12+
{
13+
public function __construct(private InitialEventHolder $initialEventHolder)
14+
{
15+
}
16+
17+
public function handle(Message $message, Closure $next): mixed
18+
{
19+
$initialEvent = $this->extractInitialEventFromHeaders($message->headers);
20+
if ($initialEvent) {
21+
$this->initialEventHolder->setInitialEvent($initialEvent);
22+
var_dump($initialEvent);
23+
}
24+
25+
return $next($message);
26+
}
27+
28+
protected function extractInitialEventFromHeaders(?array $headers): ?InitialEventDTO
29+
{
30+
$header = $headers[Config::REQUEST_HEADER] ?? '';
31+
32+
return $header ? InitialEventDTO::fromSerializedString($header) : null;
33+
}
34+
}

0 commit comments

Comments
 (0)