Skip to content

Commit a84fa33

Browse files
authored
Add message id key name to config (#315)
1 parent d15752b commit a84fa33

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

config/kafka.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,9 @@
7474
| The cache driver that will be used
7575
*/
7676
'cache_driver' => env('KAFKA_CACHE_DRIVER', env('CACHE_DRIVER', 'file')),
77-
];
77+
78+
/*
79+
| Kafka message id key name
80+
*/
81+
'message_id_key' => env('MESSAGE_ID_KEY', 'laravel-kafka::message-id'),
82+
];

src/AbstractMessage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public function getKey(): mixed
5151
/** @throws MessageIdNotSet */
5252
public function getMessageIdentifier(): string
5353
{
54-
if (! is_string($this->getHeaders()['laravel-kafka::message-id'])) {
54+
if (! is_string($this->getHeaders()[config('kafka.message_id_key')])) {
5555
throw new MessageIdNotSet();
5656
}
5757

58-
return $this->getHeaders()['laravel-kafka::message-id'];
58+
return $this->getHeaders()[config('kafka.message_id_key')];
5959
}
60-
}
60+
}

src/Consumers/Consumer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ private function getConsumerMessage(Message $message): ConsumerMessage
443443
// First, we set a new unique id that allows us to identify this message. Then
444444
// we create a new consumer message instance that will be passed as an arg
445445
// to the consumer class/closure responsible for consuming this message.
446-
if (! array_key_exists('laravel-kafka::message-id', $message->headers)) {
447-
$message->headers['laravel-kafka::message-id'] = Str::uuid()->toString();
446+
if (! array_key_exists(config('kafka.message_id_key'), $message->headers)) {
447+
$message->headers[config('kafka.message_id_key')] = Str::uuid()->toString();
448448
}
449449

450450
return app(ConsumerMessage::class, [
@@ -482,4 +482,4 @@ protected function getLastRestart(): int
482482
{
483483
return (int) Cache::driver(config('kafka.cache_driver'))->get('laravel-kafka:consumer:restart', 0);
484484
}
485-
}
485+
}

src/Message/Message.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function getHeaders(): ?array
8787
// id is already set, then array_merge will override it. It's safe to do it
8888
// here because this class is used only when we produce a new message.
8989
return array_merge(parent::getHeaders(), [
90-
'laravel-kafka::message-id' => Str::uuid()->toString(),
90+
config('kafka.message_id_key') => Str::uuid()->toString(),
9191
]);
9292
}
93-
}
93+
}

0 commit comments

Comments
 (0)