hero-zh
hero-zh

Reputation: 75

There are producer issues with spring cloud stream 3.0

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.

Upvotes: 2

Views: 2323

Answers (1)

Oleg Zhurakousky
Oleg Zhurakousky

Reputation: 6106

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

Upvotes: 5

Related Questions