java - Spring 集成 dsl : http outbound gateway

标签 java spring spring-integration dsl

面对 spring integration 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 出站 channel 适配器之前一切正常。我需要调用简单的 RESTful 接口(interface),上面的代码做得很好。但是,在 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 类型:单向 - 只处理消息并停止。另一个类似:处理请求消息并产生对输出 channel 的回复。

第一个被称为outboundChannelAdapter,对于您的 HTTP 案例,您只需发送一个 POST 请求而不必担心回复。

由于消息流在 outboundChannelAdapter 上停止,因此在集成链中不可能有任何进一步的操作。就像您的情况一样,下一个 Jms.outboundAdapter 将无法到达。

如果您真的希望从您的 REST 服务得到回复,您应该使用Http.outboundGateway。并且您的 BookStatus 将按照您希望的方式通过流中的最后一个 .handle() 发送到 JMS。

关于java - Spring 集成 dsl : http outbound gateway,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35275056/

相关文章:

error-handling - Spring Integration - 如何将错误处理委托(delegate)给单独的线程

java - 如何制作WebDriver项目的Java可执行Jar文件

java - Spring 循环依赖与范围 PROTOTYPE

java - 有什么方法可以让 Spring Data Auditing 根据字段填充 Long 或 String?

javascript - 可以是 String 或 Boolean 的 Spring 和 Json 字段映射

java - 在 Linux 上执行此 Spring 应用程序(通过 Spring Integration FTP : MessagingException 在 FTP 服务器上上传文件)时出现问题

java - Spring-Integration 聚合器无法正常工作。

java - 如何使用 Maven 作为后构建或预构建在特定位置复制文件和目录?

java - 不知道如何在java中返回一个类

java - 想要使用 selenium webdriver 代码单击下拉按钮