Decorating function beans so that they insert thread local (spring-cloud-stream-binder-kafka)

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

Decorating function beans so that they insert thread local (spring-cloud-stream-binder-kafka)

问题

我们正在使用spring-cloud-stream-binder-kafka,并且像这样将我们的消费者定义为beans:

@Bean
public Consumer<SomeEvent> someEventConsumer() {
  /* 逻辑 */
}

是否有办法为我的应用程序中的所有绑定定义一个“装饰器”?本质上,这个装饰器将查找Kafka标头并检索一个值,然后将其作为线程本地附加到消费者。

英文:

We are using spring-cloud-stream-binder-kafka and we define our consumers as beans like so:

@Bean
public Consumer&lt;SomeEvent&gt; someEventConsumer() {
  /* logic */
}

Is there any way I can define a "decorator" for all bindings in my app. Essentially this decorator will look in the kafka headers and retrieve a value and then attach it as a thread local for the consumer.

答案1

得分: 1

Add a ListenerContainerCustomizer bean and use it to add a RecordInterceptor to the binding's listener container.

英文:

Add a ListenerContainerCustomizer bean and use it to add a RecordInterceptor to the binding's listener container.

https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream.html#_advanced_consumer_configuration

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

发表评论

匿名网友

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

确定