Coding bean classes

The first class we will add is QuoteGenerated, which is an ApplicationScoped CDI bean that produces random quotes for a company every two seconds. Here's the code for this:

@ApplicationScopedpublic class QuoteGenerator {    private Random random = new Random();    @Outgoing("stock-quote")    public Flowable<String> generate() {       return Flowable.interval(2, TimeUnit.SECONDS)         .map(tick -> generateOrder(random.nextInt(2),           random.nextInt(5),   random.nextInt(100))); }    private String generateOrder(int type, int company, int amount) {       Jsonb jsonb = JsonbBuilder.create();       Operation operation = new Operation(type, Company.values()        [company], amount);       return jsonb.toJson(operation);    }}

This class produces messages that will be written to ...

Get Hands-On Cloud-Native Applications with Java and Quarkus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.