0

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?

Nikhil
  • 345
  • 2
  • 13

1 Answers1

1

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

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • I don't have input and return parameters. I read from application config (application.yaml), make an HTTP call and the send the result out via AMQP (all of this is a Spring Integration Flow). In this case how do I write the function as there is no return and no param , so can't use any of Function, Supplier, Consumer (I can use like a dummy return value and use Supplier, but does not make sense). What is he best way to implement this as AWS Lambda? May be I am missing something very basic? My entry point is a Gateway class with a method like getData(Collection configs). – Nikhil Aug 01 '20 at 22:21