Search in sources :

Example 1 with EventBusOptions

use of io.vertx.core.eventbus.EventBusOptions in project vert.x by eclipse.

the class ConnectionHolder method schedulePing.

private void schedulePing() {
    EventBusOptions options = eventBus.options();
    pingTimeoutID = vertx.setTimer(options.getClusterPingInterval(), id1 -> {
        // If we don't get a pong back in time we close the connection
        timeoutID = vertx.setTimer(options.getClusterPingReplyInterval(), id2 -> {
            // Didn't get pong in time - consider connection dead
            log.warn("No pong from server " + remoteNodeId + " - will consider it dead");
            close();
        });
        ClusteredMessage pingMessage = new ClusteredMessage<>(remoteNodeId, PING_ADDRESS, null, null, new PingMessageCodec(), true, eventBus);
        Buffer data = pingMessage.encodeToWire();
        socket.write(data);
    });
}
Also used : PingMessageCodec(io.vertx.core.eventbus.impl.codecs.PingMessageCodec) Logger(io.vertx.core.impl.logging.Logger) OutboundDeliveryContext(io.vertx.core.eventbus.impl.OutboundDeliveryContext) VertxInternal(io.vertx.core.impl.VertxInternal) LoggerFactory(io.vertx.core.impl.logging.LoggerFactory) Promise(io.vertx.core.Promise) EventBusMetrics(io.vertx.core.spi.metrics.EventBusMetrics) ConnectionBase(io.vertx.core.net.impl.ConnectionBase) Buffer(io.vertx.core.buffer.Buffer) EventBusOptions(io.vertx.core.eventbus.EventBusOptions) NodeInfo(io.vertx.core.spi.cluster.NodeInfo) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) NetSocket(io.vertx.core.net.NetSocket) Buffer(io.vertx.core.buffer.Buffer) EventBusOptions(io.vertx.core.eventbus.EventBusOptions) PingMessageCodec(io.vertx.core.eventbus.impl.codecs.PingMessageCodec)

Example 2 with EventBusOptions

use of io.vertx.core.eventbus.EventBusOptions in project vert.x by eclipse.

the class BareCommand method startVertx.

/**
 * Starts the vert.x instance.
 *
 * @return the created instance of vert.x
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
protected Vertx startVertx() {
    JsonObject optionsJson = getJsonFromFileOrString(vertxOptions, "options");
    EventBusOptions eventBusOptions;
    VertxBuilder builder;
    if (optionsJson == null) {
        eventBusOptions = getEventBusOptions();
        builder = new VertxBuilder();
    } else {
        eventBusOptions = getEventBusOptions(optionsJson.getJsonObject("eventBusOptions"));
        builder = new VertxBuilder(optionsJson);
    }
    options = builder.options();
    options.setEventBusOptions(eventBusOptions);
    beforeStartingVertx(options);
    configureFromSystemProperties.set(log);
    try {
        configureFromSystemProperties(options, VERTX_OPTIONS_PROP_PREFIX);
        if (options.getMetricsOptions() != null) {
            configureFromSystemProperties(options.getMetricsOptions(), METRICS_OPTIONS_PROP_PREFIX);
        }
        builder.init();
    } finally {
        configureFromSystemProperties.set(null);
    }
    Vertx instance;
    if (isClustered()) {
        log.info("Starting clustering...");
        eventBusOptions = options.getEventBusOptions();
        if (!Objects.equals(eventBusOptions.getHost(), EventBusOptions.DEFAULT_CLUSTER_HOST)) {
            clusterHost = eventBusOptions.getHost();
        }
        if (eventBusOptions.getPort() != EventBusOptions.DEFAULT_CLUSTER_PORT) {
            clusterPort = eventBusOptions.getPort();
        }
        if (!Objects.equals(eventBusOptions.getClusterPublicHost(), EventBusOptions.DEFAULT_CLUSTER_PUBLIC_HOST)) {
            clusterPublicHost = eventBusOptions.getClusterPublicHost();
        }
        if (eventBusOptions.getClusterPublicPort() != EventBusOptions.DEFAULT_CLUSTER_PUBLIC_PORT) {
            clusterPublicPort = eventBusOptions.getClusterPublicPort();
        }
        eventBusOptions.setHost(clusterHost).setPort(clusterPort).setClusterPublicHost(clusterPublicHost);
        if (clusterPublicPort != -1) {
            eventBusOptions.setClusterPublicPort(clusterPublicPort);
        }
        if (getHA()) {
            options.setHAEnabled(true);
            if (haGroup != null) {
                options.setHAGroup(haGroup);
            }
            if (quorum != -1) {
                options.setQuorumSize(quorum);
            }
        }
        CountDownLatch latch = new CountDownLatch(1);
        AtomicReference<AsyncResult<Vertx>> result = new AtomicReference<>();
        create(builder, ar -> {
            result.set(ar);
            latch.countDown();
        });
        try {
            if (!latch.await(2, TimeUnit.MINUTES)) {
                log.error("Timed out in starting clustered Vert.x");
                return null;
            }
        } catch (InterruptedException e) {
            log.error("Thread interrupted in startup");
            Thread.currentThread().interrupt();
            return null;
        }
        if (result.get().failed()) {
            log.error("Failed to form cluster", result.get().cause());
            return null;
        }
        instance = result.get().result();
    } else {
        instance = create(builder);
    }
    addShutdownHook(instance, log, finalAction);
    afterStartingVertx(instance);
    return instance;
}
Also used : JsonObject(io.vertx.core.json.JsonObject) EventBusOptions(io.vertx.core.eventbus.EventBusOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) VertxBuilder(io.vertx.core.impl.VertxBuilder) Vertx(io.vertx.core.Vertx) CountDownLatch(java.util.concurrent.CountDownLatch) AsyncResult(io.vertx.core.AsyncResult)

Example 3 with EventBusOptions

use of io.vertx.core.eventbus.EventBusOptions in project vert.x by eclipse.

the class BareCommand method getEventBusOptions.

/**
 * @return the event bus options.
 */
protected EventBusOptions getEventBusOptions(JsonObject jsonObject) {
    EventBusOptions eventBusOptions = jsonObject == null ? new EventBusOptions() : new EventBusOptions(jsonObject);
    configureFromSystemProperties.set(log);
    try {
        configureFromSystemProperties(eventBusOptions, VERTX_EVENTBUS_PROP_PREFIX);
    } finally {
        configureFromSystemProperties.set(null);
    }
    return eventBusOptions;
}
Also used : EventBusOptions(io.vertx.core.eventbus.EventBusOptions)

Example 4 with EventBusOptions

use of io.vertx.core.eventbus.EventBusOptions in project vert.x by eclipse.

the class EventBusExamples method example13.

public void example13() {
    VertxOptions options = new VertxOptions().setEventBusOptions(new EventBusOptions().setSsl(true).setKeyStoreOptions(new JksOptions().setPath("keystore.jks").setPassword("wibble")).setTrustStoreOptions(new JksOptions().setPath("keystore.jks").setPassword("wibble")).setClientAuth(ClientAuth.REQUIRED));
    Vertx.clusteredVertx(options, res -> {
        if (res.succeeded()) {
            Vertx vertx = res.result();
            EventBus eventBus = vertx.eventBus();
            System.out.println("We now have a clustered event bus: " + eventBus);
        } else {
            System.out.println("Failed: " + res.cause());
        }
    });
}
Also used : JksOptions(io.vertx.core.net.JksOptions) EventBusOptions(io.vertx.core.eventbus.EventBusOptions) EventBus(io.vertx.core.eventbus.EventBus) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions)

Example 5 with EventBusOptions

use of io.vertx.core.eventbus.EventBusOptions in project vert.x by eclipse.

the class EventBusExamples method example14.

public void example14() {
    VertxOptions options = new VertxOptions().setEventBusOptions(new EventBusOptions().setClusterPublicHost("whatever").setClusterPublicPort(1234));
    Vertx.clusteredVertx(options, res -> {
        if (res.succeeded()) {
            Vertx vertx = res.result();
            EventBus eventBus = vertx.eventBus();
            System.out.println("We now have a clustered event bus: " + eventBus);
        } else {
            System.out.println("Failed: " + res.cause());
        }
    });
}
Also used : EventBusOptions(io.vertx.core.eventbus.EventBusOptions) EventBus(io.vertx.core.eventbus.EventBus) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions)

Aggregations

EventBusOptions (io.vertx.core.eventbus.EventBusOptions)6 Vertx (io.vertx.core.Vertx)3 EventBus (io.vertx.core.eventbus.EventBus)3 VertxOptions (io.vertx.core.VertxOptions)2 Buffer (io.vertx.core.buffer.Buffer)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 io.vertx.core (io.vertx.core)1 AsyncResult (io.vertx.core.AsyncResult)1 Promise (io.vertx.core.Promise)1 DatagramSocket (io.vertx.core.datagram.DatagramSocket)1 DatagramSocketOptions (io.vertx.core.datagram.DatagramSocketOptions)1 MessageConsumer (io.vertx.core.eventbus.MessageConsumer)1 OutboundDeliveryContext (io.vertx.core.eventbus.impl.OutboundDeliveryContext)1 PingMessageCodec (io.vertx.core.eventbus.impl.codecs.PingMessageCodec)1 io.vertx.core.http (io.vertx.core.http)1 VertxBuilder (io.vertx.core.impl.VertxBuilder)1 VertxInternal (io.vertx.core.impl.VertxInternal)1 Logger (io.vertx.core.impl.logging.Logger)1 LoggerFactory (io.vertx.core.impl.logging.LoggerFactory)1