Search in sources :

Example 51 with Message

use of io.vertx.core.eventbus.Message in project failsafe by jhalterman.

the class VertxExample method main.

/**
 * A Vert.x sender and retryable receiver example.
 */
public static void main(String... args) throws Throwable {
    // Receiver that fails 2 times then succeeds
    AtomicInteger failures = new AtomicInteger();
    vertx.eventBus().consumer("ping-address", message -> {
        if (failures.getAndIncrement() < 2)
            message.fail(1, "Failed");
        else {
            message.reply("pong!");
        }
    });
    // Retryable sender
    Failsafe.with(retryPolicy).with(scheduler).getAsyncExecution(execution -> vertx.eventBus().send("ping-address", "ping!", reply -> {
        if (reply.succeeded())
            execution.recordResult(reply.result());
        else
            execution.recordFailure(reply.cause());
    }));
    Thread.sleep(5000);
    System.exit(0);
}
Also used : RetryPolicy(dev.failsafe.RetryPolicy) DefaultScheduledFuture(dev.failsafe.spi.DefaultScheduledFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Vertx(io.vertx.core.Vertx) Message(io.vertx.core.eventbus.Message) ReplyFailure(io.vertx.core.eventbus.ReplyFailure) Failsafe(dev.failsafe.Failsafe) Scheduler(dev.failsafe.spi.Scheduler) ReplyException(io.vertx.core.eventbus.ReplyException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 52 with Message

use of io.vertx.core.eventbus.Message in project chili-core by codingchili.

the class BusRouterTest method testRouteNodeTimeoutLogged.

@Test
public void testRouteNodeTimeoutLogged(TestContext test) {
    Async async = test.async();
    String node = UUID.randomUUID().toString();
    mockNode(node, message -> {
    });
    handle(node, ((response, status) -> {
        test.assertTrue(nodeTimeout.get());
        async.complete();
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) RunWith(org.junit.runner.RunWith) Message(io.vertx.core.eventbus.Message) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Timeout(io.vertx.ext.unit.junit.Timeout) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UUID(java.util.UUID) CoreStrings(com.codingchili.core.configuration.CoreStrings) TimeUnit(java.util.concurrent.TimeUnit) ResponseStatus(com.codingchili.core.protocol.ResponseStatus) ResponseListener(com.codingchili.core.testing.ResponseListener) RequestMock(com.codingchili.core.testing.RequestMock) JsonObject(io.vertx.core.json.JsonObject) ACCEPTED(com.codingchili.core.protocol.ResponseStatus.ACCEPTED) org.junit(org.junit) SystemContext(com.codingchili.core.context.SystemContext) Handler(io.vertx.core.Handler) Configurations.system(com.codingchili.core.files.Configurations.system) CoreContext(com.codingchili.core.context.CoreContext) Async(io.vertx.ext.unit.Async)

Example 53 with Message

use of io.vertx.core.eventbus.Message in project chili-core by codingchili.

the class BusRouterTest method testTimeout.

@Test
public void testTimeout(TestContext test) {
    Async async = test.async();
    mockNode(NODE_1, (message) -> {
    });
    handle(NODE_1, ((response, status) -> {
        test.assertEquals(ResponseStatus.ERROR, status);
        test.assertTrue(response.getString(PROTOCOL_MESSAGE).contains(system().getClusterTimeout() + ""));
        async.complete();
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) RunWith(org.junit.runner.RunWith) Message(io.vertx.core.eventbus.Message) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Timeout(io.vertx.ext.unit.junit.Timeout) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UUID(java.util.UUID) CoreStrings(com.codingchili.core.configuration.CoreStrings) TimeUnit(java.util.concurrent.TimeUnit) ResponseStatus(com.codingchili.core.protocol.ResponseStatus) ResponseListener(com.codingchili.core.testing.ResponseListener) RequestMock(com.codingchili.core.testing.RequestMock) JsonObject(io.vertx.core.json.JsonObject) ACCEPTED(com.codingchili.core.protocol.ResponseStatus.ACCEPTED) org.junit(org.junit) SystemContext(com.codingchili.core.context.SystemContext) Handler(io.vertx.core.Handler) Configurations.system(com.codingchili.core.files.Configurations.system) CoreContext(com.codingchili.core.context.CoreContext) Async(io.vertx.ext.unit.Async)

Aggregations

Message (io.vertx.core.eventbus.Message)53 JsonObject (io.vertx.core.json.JsonObject)37 Test (org.junit.Test)30 Async (io.vertx.ext.unit.Async)19 Vertx (io.vertx.core.Vertx)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17 PermittedOptions (io.vertx.ext.bridge.PermittedOptions)16 Handler (io.vertx.core.Handler)15 BridgeOptions (io.vertx.ext.bridge.BridgeOptions)15 TestContext (io.vertx.ext.unit.TestContext)15 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)14 Before (org.junit.Before)14 RunWith (org.junit.runner.RunWith)14 NetServerOptions (io.vertx.core.net.NetServerOptions)12 BridgeEventType (io.vertx.ext.bridge.BridgeEventType)12 JsonArray (io.vertx.core.json.JsonArray)11 NetClient (io.vertx.core.net.NetClient)11 NetSocket (io.vertx.core.net.NetSocket)11 FrameHelper (io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameHelper)11 FrameParser (io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser)11