2
我試圖通過設置Kafka服務器並使用生產者發送消息來在本地測試我的代碼,但我想知道是否有一種方法可以爲此編寫單元測試一段代碼(測試消費者收到的消息是否正確)。Akka Streams Kafka - 消費者的單元測試
val consumerSettings = ConsumerSettings(system,
new ByteArrayDeserializer, new StringDeserializer)
.withBootstrapServers("localhost:9092")
.withGroupId("group1")
.withProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest")
val done = Consumer.committableSource(consumerSettings,
Subscriptions.topics("topic1"))
.map { msg =>
msg.committableOffset.commitScaladsl()
}
.runWith(Sink.ignore)