Search code examples
spring-bootspring-integrationspring-amqpspring-cloud-taskspring-cloud-function

Spring Serverless HTTP Poller


I want to implement a serverless function that polls an HTTP endpoint and publishes the response to a messaging queue.

My initial thought is to build a spring boot application using spring integration gateway and adapters for HTTP polling and publishing to queue (and deploy as lambda). Is there a better option in the spring stack?

I looked at spring cloud function, spring cloud stream, spring cloud task. Any suggestions?


Solution

  • In Spring Cloud Stream this type of microservice is called source. So, you need to have a Supplier bean based on Spring Integration Java DSL to build a simple flow to let Spring Cloud Stream to poll it periodically and produce a result into bound destination.

    Something like this:

        @Bean
        public IntegrationFlow pollingHttpFlow() {
            return IntegrationFlows
                    .from(Supplier.class, gateway -> gateway.beanName("httpSupplier"))
                    .handle(Http.outboundGateway("http://somehost"))
                    .get();
        }
    

    See a blog post about this kind of interoperability: https://spring.io/blog/2019/10/25/spring-cloud-stream-and-spring-integration