diff --git a/src/Event/Kafka/KafkaRecord.php b/src/Event/Kafka/KafkaRecord.php index 4c97c3d1a..841981b82 100644 --- a/src/Event/Kafka/KafkaRecord.php +++ b/src/Event/Kafka/KafkaRecord.php @@ -19,6 +19,11 @@ public function __construct(mixed $record) $this->record = $record; } + public function getKey(): string + { + return $this->record['key']; + } + public function getTopic(): string { return $this->record['topic']; diff --git a/tests/Event/Kafka/KafkaEventTest.php b/tests/Event/Kafka/KafkaEventTest.php index e805f6dc9..9c5011361 100644 --- a/tests/Event/Kafka/KafkaEventTest.php +++ b/tests/Event/Kafka/KafkaEventTest.php @@ -19,6 +19,7 @@ public function test canonical case() self::assertSame(15, $record->getOffset()); self::assertSame(1545084650987, $record->getTimestamp()); self::assertSame('Hello, this is a test.', $record->getValue()); + self::assertSame('SGVsbG8gV29ybGQ=', $record->getKey()); self::assertSame( [ 'type' => 'core', diff --git a/tests/Event/Kafka/kafka.json b/tests/Event/Kafka/kafka.json index 94c14a47f..8d7f15cf1 100644 --- a/tests/Event/Kafka/kafka.json +++ b/tests/Event/Kafka/kafka.json @@ -9,6 +9,7 @@ "offset":15, "timestamp":1545084650987, "timestampType":"CREATE_TIME", + "key": "SGVsbG8gV29ybGQ=", "value":"SGVsbG8sIHRoaXMgaXMgYSB0ZXN0Lg==", "headers":[ {