Example usage for io.vertx.core.eventbus DeliveryOptions DEFAULT_TIMEOUT

List of usage examples for io.vertx.core.eventbus DeliveryOptions DEFAULT_TIMEOUT

Introduction

In this page you can find the example usage for io.vertx.core.eventbus DeliveryOptions DEFAULT_TIMEOUT.

Prototype

long DEFAULT_TIMEOUT

To view the source code for io.vertx.core.eventbus DeliveryOptions DEFAULT_TIMEOUT.

Click Source Link

Document

The default send timeout.

Usage

From source file:com.hubrick.vertx.kafka.consumer.KafkaConsumerVerticle.java

License:Apache License

@Override
public void start() throws Exception {
    super.start();

    final JsonObject config = vertx.getOrCreateContext().config();
    vertxAddress = getMandatoryStringConfig(config, KafkaConsumerProperties.KEY_VERTX_ADDRESS);

    configuration = KafkaConsumerConfiguration.create(
            getMandatoryStringConfig(config, KafkaConsumerProperties.KEY_GROUP_ID),
            getMandatoryStringConfig(config, KafkaConsumerProperties.KEY_KAFKA_TOPIC),
            getMandatoryStringConfig(config, KafkaConsumerProperties.KEY_ZOOKEEPER),
            config.getString(KafkaConsumerProperties.KEY_OFFSET_RESET, "largest"),
            config.getInteger(KafkaConsumerProperties.KEY_ZOOKEPER_TIMEOUT_MS, 100000),
            config.getInteger(KafkaConsumerProperties.KEY_MAX_UNACKNOWLEDGED, 100),
            config.getLong(KafkaConsumerProperties.KEY_MAX_UNCOMMITTED_OFFSETS, 1000L),
            config.getLong(KafkaConsumerProperties.KEY_ACK_TIMEOUT_SECONDS, 600L),
            config.getLong(KafkaConsumerProperties.KEY_COMMIT_TIMEOUT_MS, 5 * 60 * 1000L),
            config.getInteger(KafkaConsumerProperties.KEY_MAX_RETRIES, Integer.MAX_VALUE),
            config.getInteger(KafkaConsumerProperties.KEY_INITIAL_RETRY_DELAY_SECONDS, 1),
            config.getInteger(KafkaConsumerProperties.KEY_MAX_RETRY_DELAY_SECONDS, 10),
            config.getLong(KafkaConsumerProperties.EVENT_BUS_SEND_TIMEOUT, DeliveryOptions.DEFAULT_TIMEOUT));

    consumer = KafkaConsumer.create(vertx, configuration, this::handler);
    consumer.start();/*ww  w  .j a va 2 s.  c o m*/
}

From source file:io.nonobot.core.chat.impl.ChatRouterImpl.java

License:Apache License

private void handle(io.vertx.core.eventbus.Message<JsonObject> message) {
    JsonObject body = message.body();// www.j  a  v a 2 s  . com
    boolean respond = body.getBoolean("respond");
    String content = body.getString("content");
    String replyAddress = body.getString("replyAddress");
    String chatId = body.getString("chatId");
    for (MessageHandlerImpl handler : messageHandlers) {
        if (handler.respond == respond) {
            Matcher matcher = handler.pattern.matcher(content);
            if (matcher.matches()) {
                handler.handler.handle(new Message() {
                    boolean replied;

                    @Override
                    public String chatId() {
                        return chatId;
                    }

                    @Override
                    public String body() {
                        return content;
                    }

                    @Override
                    public String matchedGroup(int index) {
                        if (index > 0 && index <= matcher.groupCount()) {
                            return matcher.group(index);
                        } else {
                            return null;
                        }
                    }

                    @Override
                    public void reply(String msg) {
                        reply(msg, null);
                    }

                    @Override
                    public void reply(String msg, Handler<AsyncResult<Void>> ackHandler) {
                        reply(msg, DeliveryOptions.DEFAULT_TIMEOUT, ackHandler);
                    }

                    @Override
                    public void reply(String msg, long ackTimeout, Handler<AsyncResult<Void>> ackHandler) {
                        if (!replied) {
                            replied = true;
                            if (ackHandler != null) {
                                vertx.eventBus().send(replyAddress, msg,
                                        new DeliveryOptions().setSendTimeout(ackTimeout), ack -> {
                                            if (ack.succeeded()) {
                                                ackHandler.handle(Future.succeededFuture());
                                            } else {
                                                ackHandler.handle(Future.failedFuture(ack.cause()));
                                            }
                                        });
                            } else {
                                vertx.eventBus().send(replyAddress, msg);
                            }
                        } else if (ackHandler != null) {
                            ackHandler.handle(Future.failedFuture("Already replied"));
                        }
                    }
                });
                return;
            }
        }
    }
    message.reply(null);
}

From source file:microservicerx.rx.DistributedObservable.java

public static DistributedObservable toDistributable(Observable<? extends Object> in, Vertx vertx) {
    DistributedObservable result = new DistributedObservable();

    AtomicReference<MessageConsumer<String>> consumer = new AtomicReference<>(null);

    Runnable closeMsgConsumer = () -> {
        MessageConsumer<String> msgc = consumer.get();
        if (msgc != null) {
            consumer.set(null);/*from   w  w w  . j  ava 2 s  .  co  m*/
            msgc.unregister();
        }
    };

    vertx.setTimer(DeliveryOptions.DEFAULT_TIMEOUT, l -> closeMsgConsumer.run());
    consumer.set(vertx.eventBus().consumer(result.address));
    consumer.get().toObservable().subscribe(msg -> {

        in.subscribe(new ObservableToEventbus(vertx, msg.body()));

        closeMsgConsumer.run();
    });

    return result;
}