0

In the Spring integration the message channel can be configured like this:

    <int:channel id="get_send_channel" />

    <int:channel id="get_receive_channel">
       <int:queue capacity='10' />
    </int:channel>

    <int-http:outbound-gateway id="get.outbound.gateway"
       request-channel="get_send_channel" 
       url="http://localhost:8080/greeting"
       http-method="GET" reply-channel="get_receive_channel"
       expected-response-type="java.lang.String">
    </int-http:outbound-gateway>

and used like this:

@SpringBootApplication
@ImportResource("http-outbound-gateway.xml")
public class HttpApplication {

@Autowired
@Qualifier("get_send_channel")
MessageChannel getSendChannel;

@Autowired
@Qualifier("get_receive_channel")
PollableChannel getReceiveChannel;

public static void main(String[] args) {
    SpringApplication.run(HttpApplication.class, args);
}

@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
    return args -> {
        Message<?> message = MessageBuilder.withPayload("").build();
        getSendChannel.send(message);
        System.out.println(getReceiveChannel.receive().getPayload());
    };
}

How the MessageChannel can be created and registered dynamically?

Above code is from this example

I have now tried this

return IntegrationFlows.from(MessageChannels.rendezvous("getSend1"))
            .handle(Http.outboundGateway("http://localhost:8080/greeting").httpMethod(HttpMethod.GET))
            .channel(MessageChannels.queue("getReceive1")).get();

with default poller, but there is the message:

preReceive on channel 'getSend1'
postReceive on channel 'getSend1', message is null
Received no Message during the poll, returning 'false'

So the configuration seems to be incorrect and the message is not fetch from the URL.

Mike
  • 541
  • 1
  • 4
  • 18
  • 1
    I used this example for another stackoverflow question regarding something else. I think it might be what you are looking for https://github.com/teplyuska/spring-integration-example – heuts Sep 25 '18 at 15:50
  • Yes, IntegrationFlows and Java DSL can be used, https://docs.spring.io/spring-integration/docs/current/reference/html/java-dsl.html. Is it possible to read all the configurations (the URLs etc) from the database and configure the integration flows when the application starts? – Mike Sep 26 '18 at 07:02
  • 1
    I don't see why not. You could probably use the annotation @DependsOn for the class that configures your integration flows. Then you could depend on the repository where you want to read your configurations from. – heuts Sep 26 '18 at 12:31
  • Do you know how to get IntegrationFlows way (see up) working? It's quite near the solution https://stackoverflow.com/questions/40248152/spring-integration-dsl-http-outboundgateway but my implementation is not working. – Mike Sep 27 '18 at 06:51

1 Answers1

0

It is working like this:

@Bean
public IntegrationFlow inbound() {
    return IntegrationFlows
            .from(this.integerMessageSource(), c -> c.poller(Pollers.fixedRate(2000)))
            .handle(Http.outboundGateway("http://localhost:8055/greeting")
                    .httpMethod(HttpMethod.GET).expectedResponseType(String.class))
            .channel(MessageChannels.queue("getReceive"))
            .handle(Http.outboundGateway("http://localhost:8055/greeting").httpMethod(HttpMethod.POST)
                    .expectedResponseType(String.class))
            .channel(MessageChannels.queue("postReceive"))
            .handle(Http.outboundGateway("http://localhost:8055/greeting-final").httpMethod(HttpMethod.POST)
                    .expectedResponseType(String.class))
            .channel(MessageChannels.queue("postReceiveFinal"))
            .get();
}

This does get for the first URL, then posts the answer the second URL and then posts the answer to third URL and gets the final answer.

Mike
  • 541
  • 1
  • 4
  • 18