【问题标题】:Spring Cloud Stream Kafka Consumer TestSpring Cloud Stream Kafka 消费者测试
【发布时间】:2018-10-11 14:15:39
【问题描述】:

我正在尝试按照 GitHub a link 的建议设置测试

        Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka);
    DefaultKafkaProducerFactory<Integer, String> pf = new DefaultKafkaProducerFactory<>(senderProps);
    try {
        KafkaTemplate<Integer, String> template = new KafkaTemplate<>(pf, true);
        template.setDefaultTopic("words");
        template.sendDefault("foobar");

    --> ConsumerRecord<String, String> cr = KafkaTestUtils.getSingleRecord(consumer, "output");
        log.debug(cr);
    }
    finally {
        pf.destroy();
    }

StreamProcessor 设置为

@StreamListener
    @SendTo("output")
    public KStream<?, WordCount> process(@Input("input") KStream<Object, String> input) {

        return input.map((key, value) -> new KeyValue<>(value, new WordCount(value, 10, new Date(), new Date())));
    }

--> 由于@Streamprocessor 具有@SendTo("output") ,因此行从不消耗我认为应该在主题“输出”上的消息

  • 我希望能够测试流处理的消息。

【问题讨论】:

    标签: apache-kafka-streams spring-cloud-stream


    【解决方案1】:

    您需要从您的output 绑定的实际主题中消费。 你有spring.cloud.stream.bindings.output.destination的配置吗?那应该是您需要使用的值。如果您没有设置,默认值将与绑定相同 - 在这种情况下为 output

    【讨论】:

    • 我已经尝试使用私有 EmbeddedKafkaBroker EmbeddedKafka = new EmbeddedKafkaBroker(1, true, new String[] { "words", "input", "output", "counts" });
    • .web(WebApplicationType.NONE).run("--server.port=0", "--spring.jmx.enabled=false", "--spring.cloud.stream.bindings .input.destination=words", "--spring.cloud.stream.bindings.output.destination=counts",
    猜你喜欢
    • 2016-06-21
    • 2017-06-22
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 2018-03-28
    • 1970-01-01
    • 2020-11-02
    相关资源
    最近更新 更多