spring kafka 入站和出站映射头不同
我们正在使用 spring-kafka,对于与我们通信但未设置 spring_json_header_types 标头的非 spring 应用程序,我们指定某些标头应通过将它们添加为 rawMappedHeaders 来映射为字符串。我们通过设置配置为所有活页夹执行此操作: spring.cloud.stream.kafka.binder.headerMapperBeanName 作为我们为其设置 rawMappedHeaders 的默认KafkaHeaderMapper。这适用于我们拥有的生产者和消费者绑定。
然而,当我们向某些 Spring 应用程序发送出站数据时,我们实际上不想遗漏这些 rawMappedHeader 字段的 spring_json_header_types 值,因为下游应用程序尚未适应这种非 Spring 应用程序通信。
有没有一种方法可以通过配置或代码将 headerMapperBeanName 仅应用于所有生产者或仅应用于所有消费者,以便我可以让它们以不同的方式映射出站和入站标头?或者有没有更好的方法来做到这一点,DefaultKafkaHeaderMapper 本身可以处理?
we are using spring-kafka, and for non-spring apps that communicate with us that don't set the spring_json_header_types header, we are specifying that certain headers should be mapped in as Strings by adding them as rawMappedHeaders. We do this for all of our binders by setting the config:
spring.cloud.stream.kafka.binder.headerMapperBeanName as the defaultKafkaHeaderMapper which we've set rawMappedHeaders for. This applies to both the producer and consumer bindings we have.
However, when we send data outbound to some of our spring applications, we actually don't want to leave out the spring_json_header_types values for those rawMappedHeader fields, since the downstream apps have not adjusted to this non-spring app communication yet.
Is there a way through the config or code that I can apply a headerMapperBeanName to only all of the producers or only to all of the consumers so that I can have them map headers differently for outbound vs inbound? Or is there a better way of doing this that the DefaultKafkaHeaderMapper itself can handle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
绑定器级别只有一个标头映射器。
创建一个自定义的 KafkaHeaderMapper 实现可能是最简单的,该实现委托给不同的 DefaultKafkaHeaderMapper 来进行入站和出站映射。
There is only one header mapper at the binder level.
It is probably easiest to create a custom
KafkaHeaderMapper
implementation that delegates to a differentDefaultKafkaHeaderMapper
for inbound and outbound mappings.