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 ...