【问题标题】:spring integration dsl flow variables to store & retrieve with in the flowspring 集成 dsl 流变量以在流中存储和检索
【发布时间】:2018-05-02 15:00:08
【问题描述】:

我正在寻找一些流变量,我需要在其中存储诸如 orderId、customerId 和流中收到的其他响应之类的值,以便我可以在流的后期使用它们来编写业务逻辑。

    .handle(outboundGateway("localhost:8080/order?orderId={orderId}")
                            .uriVariable("orderId", m -> m.getPayload())
                            .httpMethod(HttpMethod.GET)
                            .expectedResponseType(Order.class)

    .handle(outboundGateway("localhost:8080/orderDetails?orderId={orderId}")
                            .uriVariable("orderId", m -> m.getPayload())
                            .httpMethod(HttpMethod.GET)
                            .expectedResponseType(OrderDetails.class)

    .handle(outboundGateway("localhost:8080/customer?customerId={customerId}")
                            .uriVariable("customerId", m -> ((OrderDetails)m.getPayload()).getCustomerId())
                            .httpMethod(HttpMethod.GET)
                            .expectedResponseType(Customer.class)

    .handle(outboundGateway("localhost:8080/customerAddress?addressId={addressId}")
                            .uriVariable("addressId", m -> ((Customer)m.getPayload()).getAdderssId)
                            .httpMethod(HttpMethod.GET)
                            .expectedResponseType(CustomerAddress.class)
    .handle((p, h) -> somebusinesslogic)

【问题讨论】:

    标签: spring-integration spring-integration-dsl


    【解决方案1】:

    流程中没有像state 这样的抽象。好吧,本质上,运行时根本没有流量。 IntegrationFlow 只是一个逻辑容器。将 Spring Integration 解决方案完全视为 stateless 会更好(除非我们谈论的是 aggregator)。

    不过,有一种解决方案适合您,例如将任何额外所需的信息连同其标头中的消息一起传输。这样,您在.handle() 之前使用.enrichHeaders(),并且根据ServiceActivator 的传播性质,请求标头将复制到回复消息,因此它们可用于下一个流程步骤。

    【讨论】:

    • 我尝试使用.enrich(enricherSpec -> enricherSpec.headerFunction("orderId", m -> m.getPayload())) 并且成功了,但是这些标头会在下一个出站 REST 请求中传递吗?
    • 没错。所有请求标头与 HTTP 响应标头一起复制到回复消息。见AbstractMessageProducingHandler.shouldCopyRequestHeaders()
    • 谢谢。 enricherSpec.propertyFunction 有什么用?
    • 查看它的 JavaDocs。 Enricher 也可以与 payload 一起操作。这就是为什么我建议你改用enrichHeaders()docs.spring.io/spring-integration/docs/5.0.4.RELEASE/reference/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 2018-05-31
    • 1970-01-01
    相关资源
    最近更新 更多