There are producer issues with spring cloud stream 3.0

情到浓时终转凉″ 提交于 2019-12-11 14:59:29

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/59135268/there-are-producer-issues-with-spring-cloud-stream-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!