我试图通过设置 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)