apache-kafka - 缺少嵌入式KafkaCluster?
问题描述
这篇博文https://www.confluent.io/blog/stream-processing-part-2-testing-your-streaming-application/指的是 EmbeddedKafkaCluster 类,它应该在库 kafka-streams-test 中-实用程序。
但是,库中缺少此类,例如 org.apache.kafka/kafka-streams-test-utils/2.5.1。
我以为我可以使用来自github的源代码https://github.com/a0x8o/kafka/blob/master/streams/src/test/java/org/apache/kafka/streams/integration/utils/EmbeddedKafkaCluster.java
但是这个源代码引用了一些类,例如 kafka.zk.EmbeddedZookeeper 和 kafka.utils.MockTime,我认为它们必须在像 org.apache.kafka/kafka_2.13/2.5.1 这样的库中。不幸的是,他们也失踪了。
在这种情况下,配置项目以使用 EmbeddedKafkaCluster 的最佳方法是什么?
谢谢
鲍里斯
解决方案
添加以下依赖项:
//build.gradle
testCompile group: 'junit', name: 'junit', version: '4.13'
testCompile group: 'org.hamcrest', name: 'hamcrest-junit', version: '2.0.0.0'
compile group: 'org.apache.kafka', name: 'kafka_2.13', version: '2.7.0'
testCompile group: 'org.apache.kafka', name: 'kafka_2.13', version: '2.7.0', classifier:'test'
compile group: 'org.apache.kafka', name: 'kafka-streams', version: '2.7.0'
testCompile group: 'org.apache.kafka', name: 'kafka-streams', version: '2.7.0', classifier: 'test'
compile group: 'org.apache.kafka', name: 'kafka-streams-test-utils', version: '2.7.0'
testCompile group: 'org.apache.kafka', name: 'kafka-clients', version: '2.7.0', classifier: 'test'
如果您使用的是 Maven,请根据以下代码转换所有依赖项:
//pom.xml
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<version>2.7.0</version>
<scope>test</scope>
<classifier>test</classifier>
</dependency>
并按以下方式创建 EmbeddedKafkaCluster(Kotlin 示例):
@Test
fun createEmbeddedKafkaClusterTest() {
val NUM_BROKERS = 1
val embeddedKafkaCluster = EmbeddedKafkaCluster(NUM_BROKERS)
Assert.assertNotNull(embeddedKafkaCluster)
embeddedKafkaCluster.start()
embeddedKafkaCluster.createTopic("TestTopic")
}
推荐阅读
- google-apps-script - How to send bulk emails using a Gmail email alias (changing Mailapp.SendEmail to Gmailapp.SendEmail)
- c++ - 如何在我的班级中添加对向量?
- docker - 为 Cloud Run 部署公开 8080 和 3000 端口
- c# - 如何在“开始”和“结束”字符串之间创建字符串序列
- r - 如何将地图的标题放在面板之外(tmap 包)
- javascript - 你能在另一个异步成员函数中等待一个异步成员函数吗?
- c++ - 读取访问冲突?
- python - 如何在互联网上使用 python 套接字
- r - 上传文件夹中的文件而不使用 R 引用名称
- java - Arduino - 处理双向通信无法通过串行接收数据