如何自定义ID生成@kafkalistener?
我需要能够根据@kafkalistener
的每个方法自定义ID,并基于其属性之一的值以及application.yaml
中定义的值。 ,例如:
类似方法的方法的课程。
@KafkaListener(info="myInfo")
public void listen(String msg){
}
在我的应用程序中
myapp:
myProperty: myProp
拥有一个具有 当我不明确提供注释属性时,生产的自动生成。
实现这一目标的最佳方法是什么?我正在考虑扩展kafkalistenerendpointregistrar
或beanpostProcessor
?
谢谢
I need to be able to customise the id for each method annotated with @KafkaListener
based on the value of one of it's attributes as well as a value defined in the application.yaml
, for example :
Having a class with a method annotated like so :
@KafkaListener(info="myInfo")
public void listen(String msg){
}
And a custom property in my application.yaml
myapp:
myProperty: myProp
At runtime I would like to have the id for the registered endpoint consumer to be myInfo_myProp
rather than the autogenerated one that is produced when I do not explicitly provide one in the attributes of the annotation.
What would the best way to achieve this? I was thinking of extending the KafkaListenerEndpointRegistrar
or the BeanPostProcessor
?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在调用超级类之前,覆盖端点注册表bean并在那里操纵端点属性。
这是一个例子:
Override the endpoint registry bean and manipulate the endpoint properties there, before calling the super class.
Here's an example:
请参阅该
id()
@kafkalistener
的属性的Javadocs:因此,您可以使用SPEL和属性占位符为目标侦听器容器定义动态ID。像:
See JavaDocs of that
id()
attribute of the@KafkaListener
:So, you can use SpEL and properties placeholders to define a dynamic id for the target listener container. Something like: