为什么Spring Integration Java DSL对JSON的请求不起作用

时间:2018-09-27 05:22:26

标签: spring spring-integration spring-integration-dsl

我有bean定义

    @Bean
public IntegrationFlow inbound() {
    return IntegrationFlows.from(MessageChannels.queue("getSend1"))
            .handle(Http.outboundGateway("http://localhost:8055/greeting").httpMethod(HttpMethod.GET)
                    .expectedResponseType(String.class))
            .channel(MessageChannels.queue("getReceive1"))
            .get();
}

和默认轮询器,我想从URL中获取JSON。这是行不通的。根本没有调用服务http://localhost:8055/greeting和日志消息

preReceive on channel 'getSend1'
postReceive on channel 'getSend1', message is null
Received no Message during the poll, returning 'false'

已打印。

1 个答案:

答案 0 :(得分:1)

它是这样工作的:

    @Bean
public IntegrationFlow inbound() {
    return IntegrationFlows
            .from(this.integerMessageSource(), c -> c.poller(Pollers.fixedRate(2000)))
            .handle(Http.outboundGateway("http://localhost:8055/greeting")
                    .httpMethod(HttpMethod.GET).expectedResponseType(String.class))
            .channel(MessageChannels.queue("getReceive"))
            .handle(Http.outboundGateway("http://localhost:8055/greeting").httpMethod(HttpMethod.POST)
                    .expectedResponseType(String.class))
            .channel(MessageChannels.queue("postReceive"))
            .handle(Http.outboundGateway("http://localhost:8055/greeting-final").httpMethod(HttpMethod.POST)
                    .expectedResponseType(String.class))
            .channel(MessageChannels.queue("postReceiveFinal"))
            .get();
}

这确实是第一个URL,然后将答案发布到第二个URL,然后将答案发布到第三个URL,并得到最终答案。