Spring Cloud Stream Test Binder不会填充主题标头。

huangapple go评论80阅读模式
英文:

Spring Cloud Stream Test Binder does not populate topic header

问题

当从Spring Cloud Stream测试绑定器中消费消息时,以下标头未填充:

kafka_receivedTopic

但当我连接到实际的Kafka代理时,它会填充。

是否有一种方法可以在消费者中获取主题。

我的消费者:

@Bean
public Consumer<Message<PlaneEvent>> planeEventConsumer() {
    return event -> {
        // do something
    };
}
英文:

When a message is consumed from the Spring Cloud Stream test binder, the following header is not populated:

kafka_receivedTopic

But when I connect to an actual kafka broker, it's populated.

Is there a way to get the topic in the consumer.

My consumer:

@Bean
public Consumer<Message<PlaneEvent>> planeEventConsumer() {
    return event -> {
        // do something
    };
}

答案1

得分: 0

测试绑定器确实如此;它不是一个“测试Kafka”绑定器;它是通用的。

通常最好在测试中使用真实的绑定器,带有内置代理,或者使用TestContainers。

英文:

The test binder is exactly that; it is not a "test Kafka" binder; it is generic.

It is generally better to use the real binder for tests, with an embedded broker, or TestContainers.

huangapple
  • 本文由 发表于 2023年5月10日 21:32:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76219072.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定