Spring Cloud Stream 3.0存在生产者问题 [英] There are producer issues with spring cloud stream 3.0

查看:573
本文介绍了Spring Cloud Stream 3.0存在生产者问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了有关Spring cloud stream 3.0的文档,以使用java.util.function.[Supplier/Function/Consumer]理解新的内容来代表生产者,消费和生产,消费者,这应该是正确的./p>

但是我不了解供应商.

文档指出,对供应商的轮询用于始终如一地为供应商生成数据,并且不需要计划的参与.

但是很多时候,我们需要在特定时间生成数据,例如Web请求,而我找不到任何文档或示例.

这可能与注入Supplier对象并调用get()方法一样简单,但是如何禁用轮询调用?

感谢所有提供信息的人.

解决方案

我们将更新SR1的文档,该文档将在几周后发布,但这是完整的代码,展示了如何完成所描述的内容.我们依靠项目反应堆中的EmitterProcessor:

@SpringBootApplication
@Controller
public class WebSourceApplication {

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

    EmitterProcessor<String> processor = EmitterProcessor.create();

    @RequestMapping
    @ResponseStatus(HttpStatus.ACCEPTED)
    public void delegateToSupplier(@RequestBody String body) {
        System.out.println("Sending " + body);
        processor.onNext(body);
    }

    @Bean
    public Supplier<Flux<String>> supplier() {
        return () -> processor;
    }
}

然后and then curl -H "Content-Type: text/plain" localhost:8080/ -d Hello

I read about the spring cloud stream 3.0 documents, to understand the new using java.util.function.[Supplier/Function/Consumer] to represent the producers, the consumption and production, consumers, and this should be correct.

But I don't understand Supplier.

The documentation states that polling for suppliers is used to consistently generate data for suppliers, and no program involvement is required.

But many times, we need to generate a data at a specific time, such as a web request, and I can't find any documentation or examples for that.

It might be as simple as injecting the Supplier object and calling the get() method, but how do you disable the polling call?

Thanks to all who provided the information.

解决方案

We'll update the documentation for SR1 which we'll release in few weeks, but here is the full code demonstrating how you can accomplish what you're describing. We rely on EmitterProcessor from project reactor:

@SpringBootApplication
@Controller
public class WebSourceApplication {

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

    EmitterProcessor<String> processor = EmitterProcessor.create();

    @RequestMapping
    @ResponseStatus(HttpStatus.ACCEPTED)
    public void delegateToSupplier(@RequestBody String body) {
        System.out.println("Sending " + body);
        processor.onNext(body);
    }

    @Bean
    public Supplier<Flux<String>> supplier() {
        return () -> processor;
    }
}

and then and then curl -H "Content-Type: text/plain" localhost:8080/ -d Hello

这篇关于Spring Cloud Stream 3.0存在生产者问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆