【发布时间】:2019-04-18 16:04:26
【问题描述】:
我正在尝试使用 Kafka Streams 提供的 ConsumerRecordFactory,主要是 confluent doc 来测试流应用程序,这是我到目前为止的代码:
// Properties of the application
Properties streamsConfiguration = new Properties();
// Give the Streams application a unique name. The name must be unique in the Kafka cluster
streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "testing_application");
streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "dummyserver:2181");
// Create the topology builder
StreamsBuilder builder = new StreamsBuilder();
// Run it on the test driver
TopologyTestDriver testDriver = new TopologyTestDriver(builder.build(), streamsConfiguration);
// Feed input data
ConsumerRecordFactory<String, Integer> factory = new ConsumerRecordFactory<>(
"input-topic",
new StringSerializer(),
new IntegerSerializer()
);
// Create a test record
ConsumerRecordFactory<byte[], byte[]> record = factory.create("key", 42L);
我的问题是当我编译我的代码时出现以下错误:
Error:(70, 52) java: reference to create is ambiguous
both method create(K,V,long) in org.apache.kafka.streams.test.ConsumerRecordFactory
and method create(java.lang.String,V,long) in org.apache.kafka.streams.test.ConsumerRecordFactory match
所以我知道 kafka 流定义了泛型方法 create(K,V,long),并且当我使用非泛型类型创建工厂时,我创建了一个与第一个冲突的新方法。
我的问题是我应该如何实例化我的ConsumerRecordFactory?
我尝试使用ConsumerRecordFactory<Object, Integer> 使我的工厂更通用,但推断的类型不匹配。而且我找不到其他示例,confluent github repo kafka-streams-examples 似乎没有使用ConsumerRecordFactory,而this SO answer 似乎使用与文档相同的代码。
(我知道问题更多在于 java 而不是 kafka 流,但我认为用apache-kafka-streams 标记它是接触习惯ConsumerRecordFactory 的人的好方法)
【问题讨论】:
标签: apache-kafka-streams inferred-type