英文:
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<SomeEvent> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论