Releases: nomisRev/kotlin-kafka
0.4.0
0.4.0
This release is sees a big new feature Publishing and a lot of minor improvements and fixes towards 1.0 in the receiver.
PublisherScope
A PublishScope, that can offer message (doesn't await ack), or publish which is offer + ack.
The block however waits all the offer inside, similar to coroutineScope and re-throws any failed offer.
With transaction block, that wraps the block in the correct transaction semantics and has same behavior of await offer. A transaction blocks cannot be nested, thanks @PublisherDSL.
publisher.publishScope {
offer((1..10).map {
ProducerRecord(topic.name(), "$it", "msg-$it")
})
publish((11..20).map {
ProducerRecord(topic.name(), "$it", "msg-$it")
})
transaction {
// transaction { } illegal to be called here DslMarker magic
offer((21..30).map {
ProducerRecord(topic.name(), "$it", "msg-$it")
})
publish((31..40).map {
ProducerRecord(topic.name(), "$it", "msg-$it")
})
}// Waits until all offer finished in transaction, fails if any failed
// looping
(0..100).forEach {
delay(100.milliseconds)
val record = ProducerRecord(topic.name(), "$it", "msg-$it")
offer(record)
}
// streaming
flow(1..100)
.onEach { delay(100.milliseconds) }
.map { ProducerRecord(topic.name(), "$it", "msg-$it") }
.collect { offer(it) }
}
See KafkaPublisherSpec for more examples.
Flow publish records
Often we need to receiver/consume events from Kafka, and as a result we need to publish new events to Kafka. That typically requires a streaming solution to produce records into Kafka, and keeping track of all published records into Kafka and their lifecycle and wiring that back into a stream is tricky. So we kotlin-kafka
now offers Flow.produce
build in the same style as PublisherScope
!
produce
will send message to Kafka, and stream Result
of RecordMetadata
back to the user.
It will not stop sending messages if any error occurs, you can throw it in the collector if you want the stream to stop. Otherwise, use produceOrThrow
.
Any encountered errors will be sent to the collector as [Result.failure], and they will also be rethrown if the Flow completes without handling them (e.g. using Flow.catch
). Check Kafka's [Callback] documentation for more information on when and which errors are thrown, and which are recoverable.
suspend fun publish messages(bootStrapServers: String, topic: String) {
val publisherSettings = PublisherSettings(
bootstrapServers = bootStrapServers,
keySerializer = StringSerializer(),
valueSerializer = StringSerializer()
)
(0..10_000).asFlow()
.onEach { delay(10.milliseconds) }
.map { index ->
ProducerRecord<String, String>(topic.name(), index % 4, "$index", "Message $index")
}.produce(publisherSettings)
.collect { metadata: Result<RecordMetadata> ->
metadata
.onSuccess { println("partition: ${it.partition()}, offset: ${it.offset}") }
.onFailure { println("Failed to send: $it") }
}
All, and any feedback welcome!
What's Changed
- Update dependency org.testcontainers:kafka to v1.18.2 by @renovate in #128
- Update dependency org.testcontainers:kafka to v1.18.3 by @renovate in #129
- Update dependency org.jetbrains.kotlinx.kover to v0.7.1 by @renovate in #130
- Update all dependencies by @renovate in #131
- Update dependency org.jetbrains.dokka to v1.8.20 by @renovate in #133
- Update dependency org.jetbrains.dokka to v1.9.0 by @renovate in #134
- Update all dependencies to v4 (major) by @renovate in #136
- Update all dependencies by @renovate in #135
- Update all dependencies by @renovate in #138
- Update all dependencies to v0.12.0-rc.6 by @renovate in #139
- Update all dependencies by @renovate in #140
- Update all dependencies to v3.6.0 by @renovate in #141
- Update dependency gradle to v8.4 by @renovate in #142
- Clean-up by @nomisRev in #144
- Fix workflow by @nomisRev in #145
- Switch AutoOffsetReset definition by @nomisRev in #152
- Add publish plugin by @nomisRev in #153
- Add publisher settings by @nomisRev in #154
- Remove warnings from non-deprecated code by @nomisRev in #155
- Update dependency org.jetbrains.kotlinx.kover to v0.7.4 by @renovate in #157
- Publisher scope by @nomisRev in #156
- Fix PollLoop threading, add documentation, and split functionality in smaller methods by @nomisRev in #158
- Update dependency org.jetbrains.dokka to v1.9.10 by @renovate in #160
- Update all dependencies to v1.9.20 by @renovate in #161
- Update all dependencies to v5.8.0 by @renovate in #162
- Update dependency org.testcontainers:kafka to v1.19.2 by @renovate in #163
- Update dependency org.testcontainers:kafka to v1.19.3 by @renovate in #164
- Update all dependencies by @renovate in #165
- Update actions/setup-java action to v4 by @renovate in #166
- Update all dependencies by @renovate in #167
- Update actions/upload-artifact action to v4 by @renovate in #168
- Update all dependencies by @renovate in #169
- Update dependency com.diffplug.spotless to v6.25.0 by @renovate in #174
- Update dependency org.testcontainers:kafka to v1.19.4 by @renovate in #175
- Add power-assert, add utilities, clean-up by @nomisRev in #159
- ProduceFlow, deprecate Producer.kt, by @nomisRev in #177
- Update dependency gradle to v8.6 by @renovate in #176
- Flatten EventLoop into a single class, fix warnings. by @nomisRev in #178
- Explicit api, and flatten commit offset worker by @nomisRev in #179
- Update all dependencies to v2.0.12 by @renovate in #180
- Update dependency org.testcontainers:kafka to v1.19.5 by @renovate in #181
- Update all dependencies by @renovate in #182
- Update dependency org.testcontainers:kafka to v1.19.6 by @renovate in #183
- Update all dependencies by @renovate in #184
- Stress testing by @nomisRev in #187
Full Changelog: 0.3.1...0.4.0
0.3.1
0.3.1
Fixes breaking change introduced by KotlinX Coroutines 1.7.x, reported in #127.
This release contains no actual changes except for dependency updates.
What's Changed
- Update all dependencies to v5.4.1 by @renovate in #62
- Update all dependencies to v3.2.1 by @renovate in #63
- Update dependency gradle to v7.5.1 by @renovate in #64
- Update all dependencies to v5.4.2 by @renovate in #65
- Update gradle/gradle-build-action action to v2.2.3 by @renovate in #66
- Update gradle/gradle-build-action action to v2.2.4 by @renovate in #67
- Update all dependencies to v2 (major) by @renovate in #69
- Update all dependencies by @renovate in #68
- Update gradle/gradle-build-action action to v2.3.0 by @renovate in #70
- Update all dependencies by @renovate in #71
- Update all dependencies to v2.0.1 by @renovate in #72
- Update all dependencies by @renovate in #73
- Update gradle/gradle-build-action action to v2.3.1 by @renovate in #74
- Update actions/setup-java action to v3.5.1 by @renovate in #75
- Update all dependencies to v2.0.3 by @renovate in #77
- Update all dependencies to v3.3.0 by @renovate in #78
- Update all dependencies to v1.7.20 by @renovate in #79
- Update gradle/gradle-build-action action to v2.3.2 by @renovate in #80
- Update dependency org.testcontainers:kafka to v1.17.4 by @renovate in #81
- Update all dependencies by @renovate in #82
- Update dependency org.jetbrains.kotlinx.kover to v0.6.1 by @renovate in #83
- Update actions/checkout action to v3.1.0 by @renovate in #84
- Update dependency org.testcontainers:kafka to v1.17.5 by @renovate in #85
- Update all dependencies by @renovate in #86
- Update actions/setup-java action to v3.6.0 by @renovate in #87
- Update gradle/gradle-build-action action to v2.3.3 by @renovate in #88
- Update all dependencies to v5.5.2 by @renovate in #89
- Update all dependencies to v5.5.3 by @renovate in #90
- Update all dependencies to v5.5.4 by @renovate in #91
- Update all dependencies to v1.7.21 by @renovate in #92
- Update dependency org.testcontainers:kafka to v1.17.6 by @renovate in #93
- Update all dependencies to v2.0.4 by @renovate in #94
- Update all dependencies by @renovate in #95
- Update all dependencies to v1.7.22 by @renovate in #96
- Update all dependencies by @renovate in #97
- Update actions/setup-java action to v3.8.0 by @renovate in #98
- Update all dependencies by @renovate in #99
- Update actions/setup-java action to v3.9.0 by @renovate in #100
- Remove duplicate constructor param by @nomisRev in #101
- Fix pause during rebalance by @nomisRev in #103
- Update all dependencies to v1.8.0 by @renovate in #104
- Update actions/checkout action to v3.3.0 by @renovate in #105
- Update all dependencies to v3.3.2 by @renovate in #106
- Update all dependencies to v1.8.10 by @renovate in #107
- Update all dependencies to v5.5.5 by @renovate in #108
- Update all dependencies to v3.4.0 by @renovate in #109
- Update actions/setup-java action to v3.10.0 by @renovate in #110
- Update dependency gradle to v8 by @renovate in #111
- Update gradle/gradle-build-action action to v2.4.0 by @renovate in #112
- Update all dependencies by @renovate in #113
- Update actions/checkout action to v3.4.0 by @renovate in #114
- Update all dependencies to v2.0.7 by @renovate in #115
- Update actions/checkout action to v3.5.0 by @renovate in #116
- Update actions/setup-java action to v3.11.0 by @renovate in #117
- Update all dependencies by @renovate in #118
- Update all dependencies by @renovate in #119
- Update all dependencies to v5.6.0 by @renovate in #120
- Update all dependencies to v5.6.1 by @renovate in #121
- Update dependency gradle to v8.1.1 by @renovate in #122
- Update all dependencies to v1.8.21 by @renovate in #123
- Update all dependencies to v1.7.0 by @renovate in #124
- Update all dependencies by @renovate in #125
- Update dependency org.jetbrains.kotlinx.kover to v0.7.0 by @renovate in #126
Full Changelog: 0.3.0...0.3.1
0.3.0
This release implements a custom ConsumerLoop
to make strong guarantees about committing offsets, and to hide the complexity of the low-level Java SDK.
This API is inspired by Alpakka Kafka and Reactor Kafka.
More details can be found in the PR: #58