我是一个spring集成框架的新手。以下是我的代码,我实际上是想使用SI DSL配置的HTTP出站网关进行一些HTTP调用。当我运行这段代码时 IntegrationFlow
方法被调用了,但HTTP命中并没有进行。我不知道为什么。
主类
@EnableIntegration
@Configuration
@Import({ AptHttp.class })
public class DemosiApplication {
public static void main(String[] args) {
SpringApplication.run(DemosiApplication.class, args);
}
}
配置类
@Configuration
@IntegrationComponentScan
public class AptHttp {
@EnableIntegration
public static class ContextConfiguration {
@Bean("inputChannel")
public MessageChannel inputChannel() {
return MessageChannels.direct().get();
}
@Bean
public MessageChannel outputChannel() {
return MessageChannels.direct().get();
}
@Bean
public IntegrationFlow outBoundFlow() {
System.out.println("Inside t outBoundFlow flow ");
final String uri = "http://localhost:9090/api/test";
return f -> f.channel(inputChannel())
.handle(Http.outboundGateway(uri).httpMethod(HttpMethod.GET).expectedResponseType(String.class))
.channel(outputChannel());
}
}
}
只有以上两个类。当我运行SI应用程序时,我也没有得到任何错误(sysout正在打印,但没有调用,我不知道为什么)。我有另一个应用程序,在那里我可以有一些API通过弹簧集成代码,我试图打的API方法。为了了解HTTP出站网关的流程,我正在尝试这种方式。
谁能帮我建议一下。
解决方案:
你没有显示(或者说没有)将消息发送至的代码。inputChannel
.
该 Http.outboundGateway()
并不是一个活跃的组件,它的工作必须由请求消息触发,而且在Spring应用上下文中有两个主要阶段:创建bean和运行时。
另外,在Spring应用上下文中,有两个主要阶段:创建bean和运行时。System.out.println()
在创建bean的阶段,它与运行时无关。当真正通过HTTP进行发送时,它与运行时无关。
所以,在装箱并启动一个应用上下文(SpringApplication.run(DemosiApplication.class, args);
)你需要采取 inputChannel
豆送 Message<?>
成。只有在这之后,你的HTTP出站网关才会被触发。
更多信息请参见示例。https:/github.comspring-projectsspring-integration-samples。
本文来自投稿,不代表运维实战侠立场,如若转载,请注明出处:https://www.shizhanxia.com/436.html