Skip to content

Instantly share code, notes, and snippets.

View vitormbgoncalves's full-sized avatar
🚀
Building rockets

Vitor Gonçalves vitormbgoncalves

🚀
Building rockets
View GitHub Profile
@vitormbgoncalves
vitormbgoncalves / Consumer.kt
Created February 7, 2022 04:07 — forked from cyberdelia/Consumer.kt
Kafka + Kotlin + Coroutines
package com.lapanthere.bohemia
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import org.apache.kafka.clients.consumer.ConsumerRecord
import org.apache.kafka.clients.consumer.KafkaConsumer
import java.time.Duration
fun <K, V> KafkaConsumer<K, V>.asFlow(timeout: Duration = Duration.ofMillis(500)): Flow<ConsumerRecord<K, V>> =