2
votes

I'm fairly new to Spring Integration and I'm trying to setup a simple use case:

polling a remote REST endpoint, split the returned payload into multiple lines and send it to a Kafka outbound adapter. I successfully did something analogous, which uses a File Adapter, but I'm stuck with the HTTP adapter. I don't understand how to associate a poller to a HTTP inbound adapter.

So far, my approach has been to create a simple flow:

return IntegrationFlows
  .from
    (
      Http.inboundChannelAdapter("http://localhost:8080/data")
        .requestMapping(m -> m.methods(HttpMethod.GET))
        .replyTimeout(20)
      )
  .channel(INBOUND_DEMO_CHANNEL)
  .get();

The inboundChannelAdapter doesn't seem to accept a Poller. In my previous attempt using a File, I have created a FileReadingMessageSource so that my flow looked like:

return IntegrationFlows.from(fileReadingMessageSource,
    // POLLER CONFIGURATION
    .poller(Pollers.fixedDelay(period)
    ...
    .get();

but I can't find the equivalent of a HTTP message source.

1

1 Answers

3
votes

Well, you are missing the fact that HTTP is an event-driven by nature and it is server here. You use it from the end-user perspective somehow like calling the URL from browser or some command line tool, or any other HTTP client.

Not sure what made you think that HTTP server is polling. And not sure what it should poll though...

Maybe what you need is exactly opposite - Http.outboundGateway(), where you call some remote REST service and wait for reply. But that's already not a source, it is a processor.

If you really need to call such a service periodically, you can consider to use simple polling MessageSource:

IntegrationFlows.from(() -> new GenericMessage<>(""),
      .poller(Pollers.fixedDelay(period))
  .handle(Http.outboundGateway("http://localhost:8080/data"))