春季集成 - 如何使用kotlin DSL根据标头值路由
假设我有一个标题,上面有一个名为“计数”的属性,我该如何根据该值路由?
在Kotlin DSL中有路由函数,但是我不确定如何将其配置为HeaderValuerouter
文档对Java DSL说了以下内容,但是我不清楚我如何如何可以握住路由器块中的标题。
有人有例子(Kotlin和Java DSL)吗?
春季集成本地提供专业路由器类型, 包括:
headervaluerouter
PayloadTyperouter
异常
coverentlistrouter
xpathrouter
与许多其他DSL IntegrationFlowBuilder EIP方法一样,路由() 方法可以应用任何AbstractMessagerouter实现或用于 便利性,作为Spel表达式的弦或Ref方法对。在 此外,您可以使用lambda配置Route(),然后使用lambda 消费者< Routerspec>。
Assuming I've got a header with a property called "count" on it, how do I route based on that value ?
In the Kotlin DSL there is the route function, but I'm unsure how to configure it to be a HeaderValueRouter
The documentation says the following for the Java DSL,but it isn't clear to me how I can get hold of the headers within the router block.
Does anyone have an example (Kotlin and Java DSLs ) ?
Spring Integration natively provides specialized router types,
including:HeaderValueRouter
PayloadTypeRouter
ExceptionTypeRouter
RecipientListRouter
XPathRouter
As with many other DSL IntegrationFlowBuilder EIP methods, the route()
method can apply any AbstractMessageRouter implementation or, for
convenience, a String as a SpEL expression or a ref-method pair. In
addition, you can configure route() with a lambda and use a lambda for
a Consumer<RouterSpec>.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个单元测试,演示了Kotlin DSL的可能性:
您只需要执行
route()
函数来处理整个message> Message
作为输入。然后,您可以在Lambda中访问其标题。这可能无法在Kotlin DSL文档中解释,但这是Java DSL中的内容: https://docs.spring.io/spring-integration/docs/current/current/reference/reference/html/html.html.html#java-dsl-w.jjava-dsl-class-class-class-class-cast-cast-cast-cast-cast
Here is a Unit test which demonstrates how your request is possible with Kotlin DSL:
What you just need is to enforce a
route()
function to deal with the wholeMessage
as input. Then you have access to its headers in the lambda.This might not be explained in the Kotlin DSL docs, but here is something in Java DSL: https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl-class-cast