@Override public void start(Future<Void> future) { String company = TraderUtils.pickACompany(); int numberOfShares = TraderUtils.pickANumber(); System.out.println("Java-RX compulsive trader configured for company " + company + " and shares: " + numberOfShares); ServiceDiscovery.create(vertx, discovery -> { Single<PortfolioService> retrieveThePortfolioService = RXEventBusService.rxGetProxy(discovery, PortfolioService.class, rec -> rec.getName().equalsIgnoreCase("portfolio")); Single<MessageConsumer<JsonObject>> retrieveTheMarket = MessageSource.rxGetConsumer(discovery, rec -> rec.getName().equalsIgnoreCase("market-data")); //TODO //---- // TODO 1 - "wait" for both single to be completed (using Single.zip or Single.zipWith methods) // TODO 2 - When both single have completed, attach the handler to the message consumer to execute the // trading logic // TODO 3 - Use the TraderUtils.drumpTradingLogic method returning a Completable. Don't forget to // subscribe to it, or nothing will happen. Return "true" to comply with the "zip" operator // signature. // TODO 4 - Transform the output into a Completable (toCompletable) and subscribe to it using: //.subscribe(CompletableHelper.toObserver(future)) - it reports the failure or success to the `done` // future. // To remove future.complete(); //---- }); }
/** * This method is called when the verticle is deployed. */ @Override public void start(Future<Void> future) { discovery = ServiceDiscovery.create(vertx); ConfigRetriever retriever = ConfigRetriever.create(vertx, getConfigurationOptions()); retriever.rxGetConfig() // Read the configuration, and deploy a MarketDataVerticle for each company listed in the configuration. .flatMap(config -> Observable.fromIterable(config.getJsonArray("companies")) .cast(JsonObject.class) // Deploy the verticle with a configuration. .flatMapSingle(company -> vertx.rxDeployVerticle(MarketDataVerticle.class.getName(), new DeploymentOptions().setConfig(company))) .toList() ) // Deploy another verticle .flatMap(l -> vertx.rxDeployVerticle(RestQuoteAPIVerticle.class.getName())) // Expose the market-data message source .flatMap(x -> discovery.rxPublish(MessageSource.createRecord("market-data", ADDRESS))) .subscribe((rec, err) -> { if (rec != null) { this.record = rec; future.complete(); } else { future.fail(err); } }); }
MessageSource.getConsumer(discovery, record -> record.getName().equalsIgnoreCase("my-message-source-1"), ar -> { if (ar.failed()) {