Spring 无服务器 HTTP 轮询器

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?

在 Spring Cloud Stream 中,这种类型的微服务称为 source。所以,你需要有一个基于 Spring Integration Java DSL 的 Supplier bean 来构建一个简单的流程,让 Spring Cloud Stream 定期轮询它并产生一个结果到绑定目的地。

像这样:

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

查看关于这种互操作性的博客 post:https://spring.io/blog/2019/10/25/spring-cloud-stream-and-spring-integration