[英]Spring Integration Java DSL - Reusable object in the flow
I am new to Spring Integration DSL, and I am stuck with with a problem. 我是Spring Integration DSL的新手,并且遇到了问题。 I need to use Object from beginning of the flow on a specific point in the subFlow or any other point in the flow, something like a Session variable which is reusable throughout the whole flow.
我需要在子流中特定点或流中任何其他点的流开始处使用Object,例如Session变量,它可以在整个流中重复使用。 Here is the example where I transform udp request, transform it to http request which is sent to an api function and the received response doesn't contain data needed to make udp response.
在此示例中,我转换了udp请求,将其转换为发送到api函数的http请求,并且接收到的响应不包含进行udp响应所需的数据。 So somehow I need the data which is in the udp request to make udp response.
所以以某种方式我需要udp请求中的数据来做出udp响应。 I have been thinking about the splitter but I don't think that is a solution or even extending the current Integratin flow to my needs.
我一直在考虑分离器,但我认为这不是解决方案,甚至也不是将当前的Integratin流程扩展到我的需求。 I know the system isn't loosely coupled, but it has to be a way to do this.
我知道系统并不是松散耦合的,但这必须是实现此目标的一种方法。
@Bean
public IntegrationFlow udpHttpFlow() {
return IntegrationFlows.from(udpInboundChannel())
.transform(udpRequestTransformer())
/* udp request object to use */
.<UdpRequest, Boolean>route(SessionObject::sessionExists, mapping -> mapping
.subFlowMapping(false, sf -> sf
.transform(httpRequestTransformer())
.handle(httpOutboundGateway())
.transform(httpResponseTransformer()))
/*use udp object here .handle(...) */
.subFlowMapping(true, sf -> sf
/* .handle(...) */
.transform(udpResponseTransformer())
.handle(udpOutboundChannel())
.get();
}
Solved it, used enrichHeaders method. 解决了它,使用了richHeaders方法。
@Bean
public IntegrationFlow udpHttpFlow() {
return IntegrationFlows.from(udpInboundChannel())
.transform(udpRequestTransformer())
/* save udb request object to message header */
.enrichHeaders(s -> s.headerExpressions(h -> h.put("udp", "payload")))
.<UdpRequest, Boolean>route(SessionObject::sessionExists, mapping -> mapping
.subFlowMapping(false, sf -> sf
.transform(httpRequestTransformer())
.handle(httpOutboundGateway())
.transform(httpResponseTransformer())
/* an example how to use the udp request object */
.handle((payload, headers) -> headers.get("udp")))
.subFlowMapping(true, sf -> sf
/* .handle(...) */
.transform(udpResponseTransformer())
.handle(udpOutboundChannel())
.get();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.