I am a newbie in the spring integration framework. Below is my code, I am actually trying to make some HTTP calls using HTTP outbound gateway using SI DSL configuration. When I ran the code the IntegrationFlow
methods are called but the HTTP hit is not making. I am not sure why.
Main class
@EnableIntegration
@Configuration
@Import({ AptHttp.class })
public class DemosiApplication {
public static void main(String[] args) {
SpringApplication.run(DemosiApplication.class, args);
}
}
config class
@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());
}
}
}
Above two classes only. I don't get any error too when I ran the SI application (sysout are printing but the call is not made I don't know why ). I have another application where I can have some API through the spring integration code I am trying to hit that API method. To understand the flow of HTTP outbound gateway I am trying this way.
Could anyone please help/ suggest me on this.
You don't show (or don't have) the code which sends messages into the inputChannel
.
The Http.outboundGateway()
is not an active components and its work has to be triggered by the request message.
Also there are two main phases in Spring application context: bean creation and runtime.
So, you see that System.out.println()
during bean creation phase. It has nothing to do with runtime when really a send over HTTP happens.
So, after crating and starting an application context (SpringApplication.run(DemosiApplication.class, args);
) you need to take an inputChannel
bean and send a Message<?>
into it. Only after that your HTTP Outbound Gateway is going to be triggered.
See more info in samples: https://github.com/spring-projects/spring-integration-samples