弹簧集成 - 放置在标题中的对象作为字符串而不是对象类型返回
我在Java DSL中写了一个集成流,
我要丰富消息的标题,其中包括一个AtomicInteger:
.enrichHeaders(t -> t.headerFunction(pollTime,message -> new AtomicInteger()))
如果我以相同的流程在后续的手柄方法上放置了一个断点,我可以看到标头,而不是字符串,而不是字符串原子素。
因此,如果我尝试在另一个流中检索它,这样我就会得到一个非法的论点例外:
message.getHeaders().get(pollTime,AtomicInteger.class).getAndAdd(delay);
Caused by: java.lang.IllegalArgumentException: Incorrect type specified for header 'pollTime'. Expected [class java.util.concurrent.atomic.AtomicInteger] but actual type is [class java.lang.String]
如果我在Kotlin DSL中做同样的事情,一切都很好:
enrichHeaders {
headerFunction<Any>(pollCount) {
AtomicInteger()
}
}
有人知道我在做什么错吗?
I've got an integration flow written in the Java DSL
I'm enriching the header of a message to include an AtomicInteger:
.enrichHeaders(t -> t.headerFunction(pollTime,message -> new AtomicInteger()))
If I put a breakpoint on the subsequent handle method in the same flow I can see the header and it's a String not an AtomicInteger.
So if I try to retrieve it in another flow like so I get an illegal argument exception:
message.getHeaders().get(pollTime,AtomicInteger.class).getAndAdd(delay);
Caused by: java.lang.IllegalArgumentException: Incorrect type specified for header 'pollTime'. Expected [class java.util.concurrent.atomic.AtomicInteger] but actual type is [class java.lang.String]
If I do the same thing in the Kotlin DSL it all works fine:
enrichHeaders {
headerFunction<Any>(pollCount) {
AtomicInteger()
}
}
Does anyone have any idea of what I am doing wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我创建了一个独立的项目来重现该错误,并在标题中添加了预期的AtomicInteger。
然后,我调试了我们的主要应用程序,事实证明有一个OpentRacingChannelInterceptor,它将所有标题重新编写为字符串。
This library is the culprit:
io.opentracing.contrib:opentracing-spring-messaging:0.0.5
which is transitive dependency ofio.opentracing.contrib:opentracing-spring-cloud-starter- Jaeger
看起来添加此库只是打破了春季集成。
修复程序是排除追踪自动配置:
@springbootapplication(dublude = {opentRacingChannelInterspectorautoconfiguration.class})
更新:
opentracing库现在长期维护以使其长期迁移到不同的迁移到不同追踪希望没有相同类型的问题的库。
参见
https:https://wwwww.cncf。 io/blog/2022/01/31/cncf-archives-the-opentracing-project/
I created a stand alone project to reproduce the error, and that added in the header as an expected AtomicInteger.
Then I debugged our main application and it turns out there's an OpenTracingChannelInterceptor which is re-writing all headers as Strings.
This library is the culprit:
io.opentracing.contrib:opentracing-spring-messaging:0.0.5
which is transitive dependency ofio.opentracing.contrib:opentracing-spring-cloud-starter-jaeger
It looks like adding this library just breaks Spring Integration.
The fix is to exclude the tracing autoconfiguration:
@SpringBootApplication(exclude = {OpenTracingChannelInterceptorAutoConfiguration.class})
Update:
The opentracing library is now longer maintained so the long term fix for this would be to migrate to a different tracing library that hopefully doesn't have the same type of issue.
See
https://www.cncf.io/blog/2022/01/31/cncf-archives-the-opentracing-project/