You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
KafkaProducer: events- instead of acks sequence (#96)
* `KafkaProducer`: event instead of acks sequence
Motivation:
`KafkaProducer`: we want to expose a general `KafkaProducerEvent` type
in the `AsyncSequence` that was formerly just for message
acknowledgements. This enables us to add more events such as statistics
in the future.
The reason behind having a single `AsyncSequence` for all event types
instead of having separate `AsyncSequence`s for each event type is that
we need to ensure that all events that we subscribe to in `librdkafka`
are actually consumed by the `AsyncSequence` in our `KafkaProducer`
type. Otherwise we could run out of memory.
Now by giving the user the entire events `AsyncSequence`, they decide if
they want to consume event or drop it.
> **Note**: Logs will be consumed regardless of the
> `KafkaProducerEvents` `AsyncSequence`
Modifications:
* create a new `enum` `KafkaProducerEvent`
* rename `KafkaMessageAcknowledgements` -> `KafkaProducerEvents`
* rename `KafkaProducer.makeProducerWithAcknowledgements` ->
`.makeProducerWithEvents`
* update tests
* update README
* Review Franz
Modifications:
* fix documentation typos
* `KafkaProducerEvent`: replace factory method with `init`
* create new type `KafkaProducerMessageStatus` effectively representing
if a `KafkaProducerMessage` was acknowledged or not
* fix README nit
* `KafkaDeliveryReport` type
Modifications:
* create new type `KafkaDeliveryReport` containing a message's status
and its id
* remove ID from `KafkaAcknowledgedMessage`
* remove `KafkaAcknowledgedMessageError`
* rename `KafkaProducerEvent.deliverReport` -> `.deliverReports`
* update README
* update tests
* Fix documentation nits
* Review Gus
Modifications:
* fix typos
* rename `KafkaProducerEvents.KafkaProducerEventAsyncIterator` ->
`KafkaProducerEvents.AsyncIterator`
* Fix typo
* Fix (letter) case nit
Co-authored-by: Franz Busch <[email protected]>
---------
Co-authored-by: Franz Busch <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+10-5Lines changed: 10 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -29,14 +29,14 @@ Both the `KafkaProducer` and the `KafkaConsumer` implement the [`Service`](https
29
29
30
30
### Producer API
31
31
32
-
The `send(_:)` method of `KafkaProducer` returns a message-id that can later be used to identify the corresponding acknowledgement. Acknowledgements are received through the `acknowledgements`[`AsyncSequence`](https://developer.apple.com/documentation/swift/asyncsequence). Each acknowledgement indicates that producing a message was successful or returns an error.
32
+
The `send(_:)` method of `KafkaProducer` returns a message-id that can later be used to identify the corresponding acknowledgement. Acknowledgements are received through the `events`[`AsyncSequence`](https://developer.apple.com/documentation/swift/asyncsequence). Each acknowledgement indicates that producing a message was successful or returns an error.
33
33
34
34
```swift
35
35
let broker = KafkaConfiguration.Broker(host: "localhost", port: 9092)
36
36
var config =KafkaProducerConfiguration()
37
37
config.bootstrapServers= [broker]
38
38
39
-
let (producer, acknowledgements) =try KafkaProducer.makeProducerWithAcknowledgements(
39
+
let (producer, events) =try KafkaProducer.makeProducerWithEvents(
40
40
config: config,
41
41
logger: logger
42
42
)
@@ -53,7 +53,7 @@ await withThrowingTaskGroup(of: Void.self) { group in
53
53
tryawait serviceGroup.run()
54
54
}
55
55
56
-
// Task receiving acknowledgements
56
+
// Task sending message and receiving events
57
57
group.addTask {
58
58
let messageID =try producer.send(
59
59
KafkaProducerMessage(
@@ -62,8 +62,13 @@ await withThrowingTaskGroup(of: Void.self) { group in
62
62
)
63
63
)
64
64
65
-
forawait acknowledgement in acknowledgements {
66
-
// Check if acknowledgement belongs to the sent message
65
+
forawait event in events {
66
+
switch event {
67
+
case .deliveryReports(let deliveryReports):
68
+
// Check what messages the delivery reports belong to
0 commit comments