【问题标题】:Spring Integration : REST to JMS integration giving timeout errorSpring集成:REST到JMS集成给出超时错误
【发布时间】:2017-12-03 03:02:33
【问题描述】:

您好,我正在尝试使用 Spring Integration 实现以下流程。 公开 REST 服务,操作负载,将更改后的负载写入 JMS 并响应 REST 服务。

@Bean
public IntegrationFlow httpInputFlow() {
    return IntegrationFlows
            .from(Http.inboundGateway(“/company”)
                     .requestMapping(r -> r
                             .methods(HttpMethod.POST))
                    .requestPayloadType(com.poc.model.Company.class))
            .transform(jsonToObjectTransformer())
            .channel(requestChannel())
            .get();
}

@Bean
@Transformer(inputChannel=“requestChannel”, outputChannel=“responseChannel”)
ObjectToJsonTransformer jsonToObjectTransformer() {
    return new ObjectToJsonTransformer();
}
@Bean
public DirectChannel requestChannel() {
    return MessageChannels.direct().get();
}
@Bean
public DirectChannel responseChannel() {
    return MessageChannels.direct().get();
}
@Bean
IntegrationFlow outboundFlow() throws Exception {
    return IntegrationFlows.from(responseChannel()) .handle(Jms.outboundAdapter(connectionFactory()).destination(“samplequeue”))
            .get();
}

请求负载正在到达队列。但是,REST 服务超时,没有回复。我需要将转换后的有效负载放入队列中,并将其发送到其余服务的响应中。我找不到任何可用的示例。

感谢任何帮助。

【问题讨论】:

    标签: rest spring-integration spring-jms spring-integration-dsl


    【解决方案1】:

    responseChannel 必须是 publishSubscribe 并且您应该还有一个 bridge 订阅者,以便将回复发送回 HTTP 入站网关。 Jms.outboundAdapter() 在单向组件中,不会产生任何回复。这就是您的流程停止并且不响应入口点的方式。

    你的用例可以写成这样:

    @Bean
    public IntegrationFlow httpInputFlow() {
        return IntegrationFlows
                .from(Http.inboundGateway("/company")
                        .requestMapping(r -> r
                                .methods(HttpMethod.POST))
                        .reqestPayloadType(com.poc.model.Company.class))
                .transform(jsonToObjectTransformer())
                .publishSubscribeChannel(subscribers ->
                        subscribers.subscribe(f -> f
                            .handle(Jms.outboundAdapter(connectionFactory()).destination("samplequeue"))))
                .bridge(null)
                .get();
    }
    

    publishSubscribeChannel() 提供所需的频道。 subscribers.subscribe() 添加 Jms.outboundAdapter() 作为第一个订阅者。 .bridge() 被添加为publishSubscribeChannel() 的最后一个(在我们的例子中是第二个)订阅者。

    BridgeHandler 背后的想法是将其回复发送到由Http.inboundGateway() 填充的replyChannel 标头。

    【讨论】:

    • 您能建议如何在.bridge() 中传递桥接处理程序吗? bridge 方法需要 Consumer> 作为参数。并且样本在 xml 中,而不是在 java dsl 中。
    • 必须是.brdige(null)。在 5.0 中将 Java DSL 移至 Spring Integration Core 后,我们添加了不带参数的 .bridge()
    猜你喜欢
    • 2013-02-04
    • 1970-01-01
    • 2014-08-23
    • 2013-01-06
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 2015-10-04
    • 2017-07-31
    相关资源
    最近更新 更多