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)