簡體   English   中英

Spring集成dsl:http出站網關

[英]Spring integration dsl: http outbound gateway

面對Spring集成java-dsl問題,我卡住了。 這是我的流程聲明代碼:

    @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();
    }

在我使用HTTP出站通道適配器之前,一切正常。 我需要調用簡單的RESTful接口,上面的代碼做得很好。 但是,在Jms.outboundAdapter(responseDestinationTemplate())行之后沒有任何結果,在成功調用http后沒有執行任何操作。

如果我刪除http流程部分(由評論包圍) - 它的工作原理。 實現了如此多的東西,幾乎理解並看到了整合的美感和簡潔性......這就是它。 還有一個地方我被卡住了。

以下是成功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}]

沒有錯誤,沒有任何警告。

Spring Integration提供了兩種MessageHandler類型:單向 - 只處理消息和停止。 另一個是:處理請求消息並產生對輸出通道的回復。

第一個被稱為outboundChannelAdapter ,在您的HTTP情況下,您只發送一個POST請求而不用擔心回復。

由於消息流在outboundChannelAdapter上停止,因此集成鏈中無法執行任何進一步操作。 與您的情況一樣,將無法訪問下一個Jms.outboundAdapter

如果您真的希望REST服務的reply ,您應該使用Http.outboundGateway 並且您的BookStatus將按流程中的最后一個.handle()發送到JMS。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM