Commit 5ed295f
authored
Refactor
* Refactor `KafkaProducer`
Motiviation:
* align `KafkaProducer` more with proposed changes to `KafkaConsumer`
* `AsyncStream` was not handling `AsyncSequence` termination handling as
we wanted it to, so revert back to use `NIOAsyncSequenceProducer`
Modifications:
* make `KafkaProducer` `final class` instead of `actor`
* `KafkaProducer`: use `NIOAsyncSequenceProducer` instead of
`AsyncSequence` for better termination handling -> shutdown
`KafkaProducer` on termination of the `AsyncSequence`
* introduce `StateMachine` to `KafkaProducer`
* move internal state of `KafkaProducer` to `KafkaProducer.StateMachine`
* remove unused `await` expressions when accessing `KafkaProducer`
* update tests
* update `README`
* * rename KafkaProducer.StateMachine.State.shutDown to .finished
* Remove unused awaits
* KafkaProducer: move logger out of state
* KafkaProducer: rename `killPollLoop` -> `terminatePollLoop`
* Fix errors after rebase
Modifications:
* move `NoBackPressure` struct to `extension` of
`NIOAsyncSequenceProducerBackPressureStrategies`
* break down duplicate `ShutDownOnTerminate` type into two more
specialised types for `KafkaConsumer` and `KafkaProducer`
* add missing `config` parameter to `KafkaProducer`'s initialiser
* Create wrapper for Kafka topic handle dict
Modifications:
* create new class `RDKafkaTopicHandles` that wraps a dictionary
containing all topic names with their respective `rd_kafka_topic_t` handles
* create method `KafkaClient.produce` wrapping the `rd_kafka_produce`
method in a Swift way
* Own implementation of `rd_kafka_flush()`
Modifications:
* `KafkaClient`: add new property `outgoingQueueSize`
* `KafkaProducer.StateMachine`: add new state `.flushing`
* `KafkaProducer.shutdownGracefully()`:
* make non-async
* remove invocation to `rd_kafka_flush`
* set state to `KafkaProducer.StateMachine.State` to `.flushing`
* `KafkaProducer` poll loop:
* poll as long as `outgoingQueueSize` is > 0 to send out any
enqueued `KafkaProducerMessage`s and serve any enqueued callbacks
* `KafkaProducerTests`: add test asserting that the `librdkafka` `outq`
is still being served after `KafkaProducer.shutdownGracefully` has
been invoked as long as there are enqueued items
* Review Franz
Modifications:
* rename `KafkaProducer.shutdownGracefully` to
`KafkaProducer.triggerGracefulShutdown`
* `KafkaProducer.send` separate error message when in state `.flushing`KafkaProducer (#67)1 parent 588af60 commit 5ed295f
File tree
8 files changed
+455
-176
lines changed- Sources/SwiftKafka
- RDKafka
- Utilities
- Tests
- IntegrationTests
- SwiftKafkaTests
8 files changed
+455
-176
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
45 | 86 | | |
46 | 87 | | |
47 | 88 | | |
| |||
210 | 251 | | |
211 | 252 | | |
212 | 253 | | |
| 254 | + | |
213 | 255 | | |
214 | 256 | | |
215 | 257 | | |
216 | 258 | | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
217 | 267 | | |
218 | 268 | | |
219 | 269 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 20 | + | |
29 | 21 | | |
30 | 22 | | |
31 | 23 | | |
32 | | - | |
| 24 | + | |
33 | 25 | | |
34 | 26 | | |
35 | 27 | | |
36 | | - | |
| 28 | + | |
37 | 29 | | |
38 | 30 | | |
39 | 31 | | |
| |||
68 | 60 | | |
69 | 61 | | |
70 | 62 | | |
71 | | - | |
| 63 | + | |
| 64 | + | |
72 | 65 | | |
73 | 66 | | |
74 | 67 | | |
| |||
91 | 84 | | |
92 | 85 | | |
93 | 86 | | |
94 | | - | |
95 | | - | |
| 87 | + | |
| 88 | + | |
96 | 89 | | |
97 | 90 | | |
98 | 91 | | |
| |||
123 | 116 | | |
124 | 117 | | |
125 | 118 | | |
126 | | - | |
127 | | - | |
| 119 | + | |
| 120 | + | |
128 | 121 | | |
129 | 122 | | |
130 | 123 | | |
| |||
0 commit comments