java – Spring集成dsl:http出站网关

面对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服务的回复,您应该使用Http.outboundGateway.并且您的BookStatus将按流程中的最后一个.handle()发送到JMS.

上一篇:Android编译选项eng、user、userdebug的区别


下一篇:java 比较时间,DateDiff