使用 Java DSL 的消息传递网关的回复通道

问题描述 投票:0回答:1

我有一个 REST API,它从客户端应用程序接收 POST 请求。

@Autowired
private EdiTranslationEvents.TransformToString transformToString;

@PostMapping("/testPost")
@ResponseStatus(HttpStatus.OK)
public String testPostLogging(@RequestBody Student student) {
    log.info("In controller....");
    System.out.println(this.transformToString.objectToInputGateway(student));
    return "testPost logging";
}

如您所见,在控制器中,我有一个自动连线消息网关,我正在使用它向通道发送数据。

@Configuration
@EnableIntegration
public class EdiTranslationEvents {

    @Component
    @MessagingGateway
    public interface TransformToString {

        @Gateway(requestChannel = "inputObjectChannel")
        String objectToInputGateway(Student student);
    }

    @Bean
    public IntegrationFlow inputObjectString() {
        return IntegrationFlows.from(inputObjectChannel())
                .transform(Transformers.objectToString())
                .log(LoggingHandler.Level.DEBUG, "com.dash.Logger")
                .get();
    }
}

当我将数据发送到 REST API 时,API 只是挂起。网关不返回任何内容。我指定了返回类型,并且假设网关创建一个临时回复通道并将响应发送到该通道。

但是,我没有在 DSL 配置中执行任何操作来创建或管理回复。那么,如何从 DSL 流将回复发送回回复通道?

spring-integration spring-integration-dsl
1个回答
3
投票

您当前的流程不返回值,您只是记录消息。

终止

.log()
结束流程。

删除

.log()
元素,以便转换结果将自动路由回网关。

或者在日志后面添加一个

.bridge()
(通向无处的桥梁),它将把输出桥接到回复通道。

© www.soinside.com 2019 - 2024. All rights reserved.