简体   繁体   English

测试 Flink-Kafka 集成

[英]Testing Flink-Kafka integration

How to set up a unit testing environment where I can create Kafka topics, write to them using FlinkKafkaProducer and read from them using FlinkKafkaConsumer?如何设置一个单元测试环境,我可以在其中创建 Kafka 主题,使用 FlinkKafkaProducer 写入它们并使用 FlinkKafkaConsumer 读取它们?

It seems like the functionality is there, but is not well-documented.似乎功能在那里,但没有很好的记录。

The farthest I was able to get is the following我能得到的最远的是以下

val server = new KafkaTestEnvironmentImpl()
server.prepare(KafkaTestEnvironment.createConfig().setKafkaServersNumber(1))
server.createTestTopic("my.test.topic", 1, 1)
server.shutdown()

But this throws an error java.lang.NoClassDefFoundError: kafka/admin/RackAwareMode .但这会引发错误java.lang.NoClassDefFoundError: kafka/admin/RackAwareMode I am not sure if trying to resolve this error is the best course of action or whether there is a simpler solution.我不确定尝试解决此错误是否是最好的做法,或者是否有更简单的解决方案。

I'd highly recommend to user a docker-based approach, such as testcontainers .我强烈建议用户使用基于 docker 的方法,例如testcontainers Setup of Kafka is as easy as it gets. Kafka 的设置非常简单。

If you need to inject data, there is another framework that allows you to maintain the topics and add data easily.如果您需要注入数据,还有 另一个框架可以让您轻松维护主题并添加数据。 If can be used in conjunction with testcontainers or if you really only need Kafka as an external system it can even fully replace it.如果可以与 testcontainers 结合使用,或者如果您真的只需要 Kafka 作为外部系统,它甚至可以完全替代它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM