-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Kafka Message Header API Motivation: Be able to attach headers to a `KafkaProducerMessage` and read out headers attached to a `KafkaConsumerMessage`. Modifications: * create new type `struct KafkaHeader` representing a key-value pair of `String` key and `ByteBuffer` value * add property `headers: [KafkaHeader]` to `KafkaConsumerMessage` and `KafkaConsumerMessage` * use `rd_kafka_produceva` (varidadic arguments) to produce messages as `rd_kafka_produce` did not support setting message headers * create helper class `RDKafkaUnsafeProducerMessage` that helps configuring the varidadic argument array for `rd_kafka_produceva` * add new test asserting that both producing and consuming messages with message headers works * Remove KafkaContiguousBytes TODOs * Review Franz Modifications: * no copying of `KafkaProducerMessage` headers and values -> build scoped accessor helper that recursively accesses all underlying pointers of the `KafkaProducerMessage`'s `headers: [KafkaHeader]` * only use `rd_kafka_produceva` when `message.headers.isEmpty == false` * Review Franz: simplify recursion cases
- Loading branch information
1 parent
1608c4a
commit 8592c61
Showing
6 changed files
with
384 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the swift-kafka-client open source project | ||
// | ||
// Copyright (c) 2023 Apple Inc. and the swift-kafka-client project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of swift-kafka-client project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import NIOCore | ||
|
||
/// A structure representing a header for a Kafka message. | ||
/// Headers are key-value pairs that can be attached to Kafka messages to provide additional metadata. | ||
public struct KafkaHeader: Sendable, Hashable { | ||
/// The key associated with the header. | ||
public var key: String | ||
|
||
/// The value associated with the header. | ||
public var value: ByteBuffer? | ||
|
||
/// Initializes a new Kafka header with the provided key and optional value. | ||
/// | ||
/// - Parameters: | ||
/// - key: The key associated with the header. | ||
/// - value: The optional binary value associated with the header. | ||
public init( | ||
key: String, | ||
value: ByteBuffer? = nil | ||
) { | ||
self.key = key | ||
self.value = value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.