【问题标题】:Spring integration extract payload within handler处理程序中的 Spring 集成提取有效负载
【发布时间】:2017-05-11 17:22:24
【问题描述】:

我是使用 DSL 进行 Spring 集成的新手,在 在 http 处理程序中提取有效负载,以动态构造 URI。 下面的集成流程由 AccountList Gateway 触发,它添加了 在通道上调用消息的客户 ID 值 “accountListFlow.input”。有效载荷仅包含“123766123” 这就是传递的客户 ID。

此后消息用标题丰富,然后传递 下游到处理程序。

我需要在处理程序中提取客户 ID 以动态构建 URI。我尝试了通用处理程序并将有效负载转换为字符串,但未能说不能转换 lambda 对象。任何帮助在这里如何 提取作为一个整体的有效载荷,这是客户ID 请构造 URI?

@MessagingGateway
public interface AccountList {

    @Gateway(requestChannel = "accountListFlow.input")
    List<String> accountListFlow(String customerId);
}


@Bean
public IntegrationFlow accountListFlow() {
    return flow -> flow.publishSubscribeChannel(s -> s.applySequence(true)
                            .subscribe(f -> f
                                       .enrichHeaders(h -> h.header("X-CUST-IP-Id","145.26.54.24"))
                            .handle((o, map) -> 
Http.outboundGateway("http://get-customers-product-holdings-gb-hbeu-v3-v3-cert.cf.wgdc-drn-01.cloud.uk/api/customers/"+(String)o+"/product-holdings?categoryCode=cc,cbs,sd")
    .httpMethod(HttpMethod.GET)
    .mappedRequestHeaders("X-CUST-IP-Id")
    .expectedResponseType(String.class)
    .extractPayload(true)).channel("aggregateAccount.input"));
}

【问题讨论】:

    标签: lambda spring-integration dsl


    【解决方案1】:

    试试……

    .handle(Http.outboundGateway("http://get-customers-product-holdings-gb-hbeu-v3-v3-cert.cf.wgdc-drn-01.cloud.uk/api/customers/{customer}/product-holdings?categoryCode=cc,cbs,sd")
        .httpMethod(HttpMethod.GET)
        .mappedRequestHeaders("X-CUST-IP-Id")
        .expectedResponseType(String.class)
        .uriVariable("customer", "payload")
        .extractPayload(true))
    .channel("aggregateAccount.input"));
    

    注意 url 中的 {customer} 变量。

    【讨论】:

    • 非常感谢加里。它按预期工作。我不能使用有效负载作为值,但 uriVariable("customerId", message -> message.getPayload().toString()) 解决了它!
    • 抱歉,payload 应该是 "payload"
    猜你喜欢
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    • 2013-03-30
    • 1970-01-01
    相关资源
    最近更新 更多