此博客条目https://www.confluent.io/blog/stream-processing-part-2-testing-your-streaming-application/指的是EmbeddedKafkaCluster类,它应该在库kafka流测试utils中。
然而,这个类在库中丢失了,例如org.apache.kafka/kafka流测试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.LockTime,我认为它们必须在org.apache.kafka/kafka_2.13/22.5.1这样的库中。不幸的是,他们也失踪了。
在这种情况下,将项目配置为使用EmbeddedKafkaCluster的最佳方式是什么?
感谢
Boris
添加以下依赖项:
//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")
}