![](/img/trans.png)
[英]Force alpakka kafka consumer show error message on deserialization error
[英]Alpakka kafka consumer offset
我在 scala 中使用 Alpakka-kafka 來使用 Kafka 主題。 這是我的代碼:
val kafkaConsumerSettings: ConsumerSettings[String, String] =
ConsumerSettings(actorSystem, new StringDeserializer, new StringDeserializer)
.withBootstrapServers(kafkaConfig.server)
.withGroupId(kafkaConfig.group)
.withProperties(
ConsumerConfig.MAX_POLL_RECORDS_CONFIG -> "100",
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG -> "earliest",
CommonClientConfigs.SECURITY_PROTOCOL_CONFIG -> "SSL"
)
Consumer
.plainSource(kafkaConsumerSettings, Subscriptions.topics(kafkaConfig.topic))
.runWith(Sink.foreach(println))
但是,消費者僅從主題中的第一條未提交消息開始輪詢。 無論提交的消息如何,我都希望始終從偏移量 0 開始。 使用 Alpakka 消費者,如何手動指定偏移量?
我想你想添加幾個配置條目:
ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG -> False
所以你的工作永遠不會保存任何偏移量
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG -> "earliest"
所以你的工作從頭開始。
如果您的工作過去已經提交了偏移量,您可能必須將其偏移量重置為最早。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.