Apache kafka streams KafkaStreams如何实例化ConsumerRecordFactory?

Apache kafka streams KafkaStreams如何实例化ConsumerRecordFactory?,apache-kafka-streams,inferred-type,Apache Kafka Streams,Inferred Type,我正在尝试使用Kafka Streams提供的ConsumerRecordFactory来测试流媒体应用程序,以下是我迄今为止的代码: // Properties of the application Properties streamsConfiguration = new Properties(); // Give the Streams application a unique name. The name must be unique in the Kafka cluster str

我正在尝试使用Kafka Streams提供的
ConsumerRecordFactory
来测试流媒体应用程序,以下是我迄今为止的代码:

// 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);
因此我知道kafka streams定义了泛型方法
create(K,V,long)
,当我用非泛型类型创建工厂时,我创建了一个与第一个方法冲突的新方法

我的问题是如何实例化我的
消费者记录工厂

我尝试使用
ConsumerRecordFactory
使我的工厂更通用,但是推断的类型不匹配。我找不到其他例子,合流的github repo似乎没有使用
ConsumerRecordFactory
,似乎使用了与文档相同的代码


(我知道问题更多的是关于java而不是关于kafka streams,但我认为用
apache kafka streams
标记它是接触习惯
消费者记录工厂的人的好方法)

以下代码中有一些问题:

// 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);

关于类型错误,您是对的,它是过去的一个坏拷贝,但不是我的实际代码。关于你的解决方案,工厂似乎正在运行,但我不明白为什么不在工厂中定义主题名称,而是在记录中解决问题?太好了。当您的字符串是字符串时,会出现这种歧义。但是如果您定义了其他一些密钥类型,它将起作用,因为方法签名是唯一的。您可以在这里找到更多详细信息:,如果您认为它解决了您的问题,请随意接受/投票回答:)是的,我只是在接受之前阅读了文档并进行了更多测试:)
// 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);
ConsumerRecordFactory<String, Integer> factory = new ConsumerRecordFactory<>( 
        new StringSerializer(),
        new IntegerSerializer()
);
// Use ConsumerRecord here instead of ConsumerRecordFactory
ConsumerRecord<byte[], byte[]> record = factory.create("input-topic","key", 42);