简体   繁体   English

Spring集成dsl:http出站网关

[英]Spring integration dsl: http outbound gateway

Faced spring integration java-dsl issue, I'm stuck. 面对Spring集成java-dsl问题,我卡住了。 This is a code I have for my flow declaration: 这是我的流程声明代码:

    @Bean
    public IntegrationFlow orchestrationFlow() {
        return IntegrationFlows.from(
                Jms.messageDrivenChannelAdapter(queueConnectionFactory())
                        .destination(bookingQueue())
                        .outputChannel(bookingChannel()))
                .<String, BookingRequest>transform(s -> {
                    Ticket t = new Gson().fromJson(s, Ticket.class);
                    return new BookingRequest()
                            .setMovieId(t.getMovie().getId())
                            .setRow(t.getSeat().getRow())
                            .setSeat(t.getSeat().getNumber())
                            .setScreenNumber(t.getScreenNumber()
                            );
                })
                // HTTP part goes here
                .<BookingRequest, HttpEntity>transform(HttpEntity::new)
                .handle(
                        Http.outboundChannelAdapter(bookingServerUrl)
                                .httpMethod(HttpMethod.POST)
                                .extractPayload(true)
                                .expectedResponseType(BookStatus.class)
                )
                // and here HTTP part ends
                .handle(
                        Jms.outboundAdapter(responseDestinationTemplate())
                )
                .get();
    }

And everything was OK until I utilized HTTP outbound channel adapter. 在我使用HTTP出站通道适配器之前,一切正常。 I need to call simple RESTful interface and code above does it pretty well. 我需要调用简单的RESTful接口,上面的代码做得很好。 But, following Jms.outboundAdapter(responseDestinationTemplate()) line leads to nothing, no action performes after successfull http call. 但是,在Jms.outboundAdapter(responseDestinationTemplate())行之后没有任何结果,在成功调用http后没有执行任何操作。

If I remove http flow part (surrounded by comments) - it works. 如果我删除http流程部分(由评论包围) - 它的工作原理。 Implemented so much stuff, almost understood and saw beauty and simplicity of integration ...aand this is it. 实现了如此多的东西,几乎理解并看到了整合的美感和简洁性......这就是它。 Yet another place I got stuck in. 还有一个地方我被卡住了。

And here are log after success REST call: 以下是成功REST调用后的日志:

2016-02-08 21:01:22.155 DEBUG 18209 --- [enerContainer-1] o.s.web.client.RestTemplate              : POST request for "http://localhost:9052/api/book" resulted in 200 (OK)
2016-02-08 21:01:22.156 DEBUG 18209 --- [enerContainer-1] o.s.web.client.RestTemplate              : Reading [class c.e.m.integration.domain.BookStatus] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@6b9469bd]
2016-02-08 21:01:22.168 DEBUG 18209 --- [enerContainer-1] i.h.o.HttpRequestExecutingMessageHandler : handler 'org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler#0' produced no reply for request Message: GenericMessage [payload=<BookingRequest(movieId=0, row=1, seat=1, screenNumber=1),{}>, headers={jms_redelivered=false, jms_replyTo=queue://statusChannel, jms_correlationId=5021291a-d4d5-47ca-b591-b6f311378688, correlationId=1d41f05a-3695-4adb-87b0-d75c17bbc3ad, id=a1fb2a2f-5d78-3183-d409-3f60aae74a20, priority=4, jms_timestamp=1454950877264, jms_messageId=ID:ins-laptop-31198-1454948247657-1:9:1:1:1, timestamp=1454950877352}]
2016-02-08 21:01:22.168 DEBUG 18209 --- [enerContainer-1] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'inboundFlow.channel#2', message: GenericMessage [payload=<BookingRequest(movieId=0, row=1, seat=1, screenNumber=1),{}>, headers={jms_redelivered=false, jms_replyTo=queue://statusChannel, jms_correlationId=5021291a-d4d5-47ca-b591-b6f311378688, correlationId=1d41f05a-3695-4adb-87b0-d75c17bbc3ad, id=a1fb2a2f-5d78-3183-d409-3f60aae74a20, priority=4, jms_timestamp=1454950877264, jms_messageId=ID:ins-laptop-31198-1454948247657-1:9:1:1:1, timestamp=1454950877352}]
2016-02-08 21:01:22.168 DEBUG 18209 --- [enerContainer-1] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'inboundFlow.channel#1', message: GenericMessage [payload=BookingRequest(movieId=0, row=1, seat=1, screenNumber=1), headers={jms_redelivered=false, jms_replyTo=queue://statusChannel, jms_correlationId=5021291a-d4d5-47ca-b591-b6f311378688, correlationId=1d41f05a-3695-4adb-87b0-d75c17bbc3ad, id=859af23d-214f-4400-e9cb-7d40308755cd, priority=4, jms_timestamp=1454950877264, jms_messageId=ID:ins-laptop-31198-1454948247657-1:9:1:1:1, timestamp=1454950877350}]
2016-02-08 21:01:22.168 DEBUG 18209 --- [enerContainer-1] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'inboundFlow.channel#0', message: GenericMessage [payload={"screenNumber":1,"seat":{"row":1,"number":1},"movie":{"id":0,"name":"The Matrix"}}, headers={jms_redelivered=false, jms_replyTo=queue://statusChannel, jms_correlationId=5021291a-d4d5-47ca-b591-b6f311378688, correlationId=1d41f05a-3695-4adb-87b0-d75c17bbc3ad, id=636638ed-aec2-082e-6181-0484999fd807, priority=4, jms_timestamp=1454950877264, jms_messageId=ID:ins-laptop-31198-1454948247657-1:9:1:1:1, timestamp=1454950877331}]

No errors, no warnings at all. 没有错误,没有任何警告。

Spring Integration provides two MessageHandler types: one-way - just handle message and stop. Spring Integration提供了两种MessageHandler类型:单向 - 只处理消息和停止。 And another one is like: handle request message and produce reply to the output channel. 另一个是:处理请求消息并产生对输出通道的回复。

The first one is called like outboundChannelAdapter and with your HTTP case you just only send a POST request and don't worry about the reply. 第一个被称为outboundChannelAdapter ,在您的HTTP情况下,您只发送一个POST请求而不用担心回复。

Since the message flow is stopped on the outboundChannelAdapter no any further action is possible in the integration chain. 由于消息流在outboundChannelAdapter上停止,因此集成链中无法执行任何进一步操作。 Like in your case the next Jms.outboundAdapter won't be reached. 与您的情况一样,将无法访问下一个Jms.outboundAdapter

If you really expect the reply from your REST service you should use Http.outboundGateway instead. 如果您真的希望REST服务的reply ,您应该使用Http.outboundGateway And your BookStatus will be sent to the JMS as you'd like by your last .handle() in the flow. 并且您的BookStatus将按流程中的最后一个.handle()发送到JMS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Integration Java DSL - Http Outbound Gateway uri 变量表达式 - Spring Integration Java DSL - Http Outbound Gateway uri variable Expression Spring Integration DSL - 可以访问标头的出站网关 - Spring Integration DSL - Outbound Gateway with access to Headers Spring Integration Java DSL - 如何调用int-http:outbound-gateway? - Spring Integration Java DSL - How to invoke int-http:outbound-gateway? Http 出站网关正在工作但未拨打电话 - 使用 spring 集成 DSL java - Http outbound gateway is working but not making the call - using spring integration DSL java Spring Integration Http Outbound Gateway Header Mapper - Spring Integration Http Outbound Gateway Header Mapper 在 Spring Integration 中使用 Http Outbound Gateway 进行错误处理 - Error handling with Http Outbound Gateway in Spring Integration Spring Integration http出站网关和UTF-8 - Spring Integration http outbound-gateway and UTF-8 Spring Integration单元测试http:outbound-gateway - Spring Integration unit test http:outbound-gateway Spring Integration-网址变量在http:outbound-gateway中不起作用 - Spring Integration - url-variable not working in http:outbound-gateway 在 Spring Integration 中使用 Transformer 轮询 HTTP 服务(出站网关)和流程 - Polling HTTP Service(Outbound Gateway) & process using Transformer in Spring Integration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM