當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageConsumer類代碼示例

本文整理匯總了Java中io.vertx.reactivex.core.eventbus.MessageConsumer的典型用法代碼示例。如果您正苦於以下問題:Java MessageConsumer類的具體用法?Java MessageConsumer怎麽用?Java MessageConsumer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MessageConsumer類屬於io.vertx.reactivex.core.eventbus包,在下文中一共展示了MessageConsumer類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import io.vertx.reactivex.core.eventbus.MessageConsumer; //導入依賴的package包/類
@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();
        //----

    });
}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:39,代碼來源:RXCompulsiveTraderVerticle.java

示例2: start

import io.vertx.reactivex.core.eventbus.MessageConsumer; //導入依賴的package包/類
/**
 * Starts the verticle asynchronously. The the initialization is completed, it calls
 * `complete()` on the given {@link Future} object. If something wrong happens,
 * `fail` is called.
 *
 * @param future the future to indicate the completion
 */
@Override
public void start(Future<Void> future) {
    // creates the jdbc client.

    ServiceDiscovery.create(vertx, discovery -> {

        // Discover and configure the database.
        Single<JDBCClient> jdbc = JDBCDataSource.rxGetJDBCClient(discovery,
            svc -> svc.getName().equals("audit-database"),
            getDatabaseConfiguration()
        ).doOnSuccess(jdbcClient -> this.jdbc = jdbcClient);

        // TODO
        // ----

        Single<MessageConsumer<JsonObject>> readySingle = Single
            .error(new UnsupportedOperationException("Not implemented yet"));

        // ----

        // signal a verticle start failure
        readySingle.doOnSuccess(consumer -> {
            // on success we set the handler that will store message in the database
            consumer.handler(message -> storeInDatabase(message.body()));
        }).subscribe(consumer -> {
            // complete the verticle start with a success
            future.complete();
            // indicate our readiness state
            ready = true;
        }, future::fail);
    });


}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:42,代碼來源:AuditVerticle.java

示例3: start

import io.vertx.reactivex.core.eventbus.MessageConsumer; //導入依賴的package包/類
/**
 * Starts the verticle asynchronously. The the initialization is completed, it calls
 * `complete()` on the given {@link Future} object. If something wrong happens,
 * `fail` is called.
 *
 * @param future the future to indicate the completion
 */
@Override
public void start(Future<Void> future) {
    // creates the jdbc client.

    ServiceDiscovery.create(vertx, discovery -> {

        // Discover and configure the database.
        Single<JDBCClient> jdbc = JDBCDataSource.rxGetJDBCClient(discovery,
            svc -> svc.getName().equals("audit-database"),
            getDatabaseConfiguration()
        ).doOnSuccess(jdbcClient -> this.jdbc = jdbcClient);

        // TODO
        // ----

        Single<JDBCClient> databaseReady = jdbc
            .flatMap(client -> initializeDatabase(client, true));
        Single<HttpServer> httpServerReady = configureTheHTTPServer();
        Single<MessageConsumer<JsonObject>> messageConsumerReady = retrieveThePortfolioMessageSource();

        Single<MessageConsumer<JsonObject>> readySingle = Single.zip(databaseReady, httpServerReady,
            messageConsumerReady, (db, http, consumer) -> consumer);

        // ----

        // signal a verticle start failure
        readySingle.doOnSuccess(consumer -> {
            // on success we set the handler that will store message in the database
            consumer.handler(message -> storeInDatabase(message.body()));
        }).subscribe(consumer -> {
            // complete the verticle start with a success
            future.complete();
            ready = true;
        }, future::fail);
    });


}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:46,代碼來源:AuditVerticle.java

示例4: eventBusMessages

import io.vertx.reactivex.core.eventbus.MessageConsumer; //導入依賴的package包/類
public void eventBusMessages(Vertx vertx) {
  EventBus eb = vertx.eventBus();
  MessageConsumer<String> consumer = eb.<String>consumer("the-address");
  Observable<Message<String>> observable = consumer.toObservable();
  Disposable sub = observable.subscribe(msg -> {
    // Got message
  });

  // Unregisters the stream after 10 seconds
  vertx.setTimer(10000, id -> {
    sub.dispose();
  });
}
 
開發者ID:vert-x3,項目名稱:vertx-rx,代碼行數:14,代碼來源:RxifiedExamples.java

示例5: start

import io.vertx.reactivex.core.eventbus.MessageConsumer; //導入依賴的package包/類
@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)
        retrieveThePortfolioService.zipWith(retrieveTheMarket, (ps, consumer) -> {

        // TODO 2 - When both single have completed, attach the handler to the message consumer to execute the
            // trading logic

            consumer.handler(message ->
                // 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.
                
                TraderUtils.dumbTradingLogic(company, numberOfShares, ps, message.body()).subscribe());
            // We need to return something as requested by the "zip" signature.
            return true;
        })

            // 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.
            .toCompletable()
            .subscribe(CompletableHelper.toObserver(future));
        //----

    });
}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:44,代碼來源:RXCompulsiveTraderVerticle.java

示例6: retrieveThePortfolioMessageSource

import io.vertx.reactivex.core.eventbus.MessageConsumer; //導入依賴的package包/類
private Single<MessageConsumer<JsonObject>> retrieveThePortfolioMessageSource() {
    // Example of Single returning a single item already known:
    return Single.just(vertx.eventBus().consumer("portfolio"));
}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:5,代碼來源:AuditVerticle.java

示例7: eventBusBodies

import io.vertx.reactivex.core.eventbus.MessageConsumer; //導入依賴的package包/類
public void eventBusBodies(Vertx vertx) {
  EventBus eb = vertx.eventBus();
  MessageConsumer<String> consumer = eb.<String>consumer("the-address");
  Observable<String> observable = consumer.bodyStream().toObservable();
}
 
開發者ID:vert-x3,項目名稱:vertx-rx,代碼行數:6,代碼來源:RxifiedExamples.java


注:本文中的io.vertx.reactivex.core.eventbus.MessageConsumer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。