如何解决EmbeddedKafkaCluster丢失了吗?
此博客条目https://www.confluent.io/blog/stream-processing-part-2-testing-your-streaming-application/引用了EmbeddedKafkaCluster类,该类应该在kafka-streams-test-utils库中。
但是,该类在库中丢失,例如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
的源代码但是此源代码引用了某些类,例如我假设必须在org.apache.kafka / kafka_2.13 / 2.5.1之类的库中找到kafka.zk.EmbeddedZookeeper和kafka.utils.MockTime。不幸的是,他们也丢失了。
在这种情况下,配置项目以使用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',version: '2.7.0',classifier:'test'
compile group: 'org.apache.kafka',name: 'kafka-streams',classifier: 'test'
compile group: 'org.apache.kafka',name: 'kafka-streams-test-utils',version: '2.7.0'
testCompile group: 'org.apache.kafka',name: 'kafka-clients',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")
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。