Search in sources :

Example 1 with BridgeOptions

use of io.vertx.ext.bridge.BridgeOptions in project vertx-tcp-eventbus-bridge by vert-x3.

the class TcpEventBusBridgeEchoServer method main.

public static void main(String[] args) {
    Vertx vertx = Vertx.vertx();
    EventBus eb = vertx.eventBus();
    eb.consumer("hello", (Message<JsonObject> msg) -> {
        msg.reply(new JsonObject().put("value", "Hello " + msg.body().getString("value")));
    });
    eb.consumer("echo", (Message<JsonObject> msg) -> msg.reply(msg.body()));
    eb.consumer("echo2", (Message<JsonObject> msg) -> {
        if ("send".equals(msg.body().getString("response_type"))) {
            eb.send("echo2_response", msg.body());
        } else {
            eb.publish("echo2_response", msg.body());
        }
    });
    TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("hello")).addInboundPermitted(new PermittedOptions().setAddress("echo")).addOutboundPermitted(new PermittedOptions().setAddress("echo")).addInboundPermitted(new PermittedOptions().setAddress("echo2")).addOutboundPermitted(new PermittedOptions().setAddress("echo2_response")));
    bridge.listen(7000, res -> System.out.println("Ready"));
}
Also used : Message(io.vertx.core.eventbus.Message) TcpEventBusBridge(io.vertx.ext.eventbus.bridge.tcp.TcpEventBusBridge) JsonObject(io.vertx.core.json.JsonObject) BridgeOptions(io.vertx.ext.bridge.BridgeOptions) EventBus(io.vertx.core.eventbus.EventBus) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) Vertx(io.vertx.core.Vertx)

Example 2 with BridgeOptions

use of io.vertx.ext.bridge.BridgeOptions in project vertx-tcp-eventbus-bridge by vert-x3.

the class TcpEventBusBridgeEventTest method before.

@Before
public void before(TestContext context) {
    vertx = Vertx.vertx();
    final Async async = context.async();
    vertx.eventBus().consumer("hello", (Message<JsonObject> msg) -> msg.reply(new JsonObject().put("value", "Hello " + msg.body().getString("value"))));
    vertx.eventBus().consumer("echo", (Message<JsonObject> msg) -> msg.reply(msg.body()));
    vertx.setPeriodic(1000, __ -> vertx.eventBus().send("ping", new JsonObject().put("value", "hi")));
    TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("hello")).addInboundPermitted(new PermittedOptions().setAddress("echo")).addInboundPermitted(new PermittedOptions().setAddress("test")).addOutboundPermitted(new PermittedOptions().setAddress("echo")).addOutboundPermitted(new PermittedOptions().setAddress("ping")), new NetServerOptions().setSsl(true).setTrustStoreOptions(new JksOptions().setPath("server.truststore").setPassword("wibble")).setKeyStoreOptions(new JksOptions().setPath("server.keystore").setPassword("wibble")), be -> {
        Logger l = LoggerFactory.getLogger(this.getClass().getName());
        l.info("Handled a bridge event " + be.getRawMessage());
        if (be.socket().isSsl()) {
            try {
                for (X509Certificate c : be.socket().peerCertificateChain()) {
                    l.info(c.getSubjectDN().toString());
                }
            } catch (SSLPeerUnverifiedException e) {
                l.warn("Caught SSLPeerUnverifiedException when processing peerCertificateChain ");
            // @fixme should have a test truststore/keystore that validates, the ones i made still throw this
            }
        }
        be.complete(true);
    });
    bridge.listen(7000, res -> {
        context.assertTrue(res.succeeded());
        async.complete();
    });
}
Also used : Message(io.vertx.core.eventbus.Message) Async(io.vertx.ext.unit.Async) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) JsonObject(io.vertx.core.json.JsonObject) BridgeOptions(io.vertx.ext.bridge.BridgeOptions) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) Logger(io.vertx.core.logging.Logger) X509Certificate(javax.security.cert.X509Certificate) Before(org.junit.Before)

Example 3 with BridgeOptions

use of io.vertx.ext.bridge.BridgeOptions in project vertx-tcp-eventbus-bridge by vert-x3.

the class TCPBridgeExamples method example1.

public void example1(Vertx vertx) {
    TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("in")).addOutboundPermitted(new PermittedOptions().setAddress("out")));
    bridge.listen(7000, res -> {
        if (res.succeeded()) {
        // succeed...
        } else {
        // fail...
        }
    });
}
Also used : TcpEventBusBridge(io.vertx.ext.eventbus.bridge.tcp.TcpEventBusBridge) BridgeOptions(io.vertx.ext.bridge.BridgeOptions) PermittedOptions(io.vertx.ext.bridge.PermittedOptions)

Example 4 with BridgeOptions

use of io.vertx.ext.bridge.BridgeOptions in project vertx-tcp-eventbus-bridge by vert-x3.

the class TcpEventBusBridgeTest method before.

@Before
public void before(TestContext context) {
    vertx = Vertx.vertx();
    final Async async = context.async();
    vertx.eventBus().consumer("hello", (Message<JsonObject> msg) -> msg.reply(new JsonObject().put("value", "Hello " + msg.body().getString("value"))));
    vertx.eventBus().consumer("echo", (Message<JsonObject> msg) -> msg.reply(msg.body()));
    vertx.setPeriodic(1000, __ -> vertx.eventBus().send("ping", new JsonObject().put("value", "hi")));
    TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("hello")).addInboundPermitted(new PermittedOptions().setAddress("echo")).addInboundPermitted(new PermittedOptions().setAddress("test")).addOutboundPermitted(new PermittedOptions().setAddress("echo")).addOutboundPermitted(new PermittedOptions().setAddress("ping")), new NetServerOptions(), event -> eventHandler.handle(event));
    bridge.listen(7000, res -> {
        context.assertTrue(res.succeeded());
        async.complete();
    });
}
Also used : Message(io.vertx.core.eventbus.Message) Async(io.vertx.ext.unit.Async) NetServerOptions(io.vertx.core.net.NetServerOptions) JsonObject(io.vertx.core.json.JsonObject) BridgeOptions(io.vertx.ext.bridge.BridgeOptions) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) Before(org.junit.Before)

Example 5 with BridgeOptions

use of io.vertx.ext.bridge.BridgeOptions in project vertx-tcp-eventbus-bridge by vert-x3.

the class TcpEventBusBridgeInteropTest method before.

@Before
public void before(TestContext context) {
    vertx = Vertx.vertx();
    final Async async = context.async();
    vertx.eventBus().consumer("hello", (Message<JsonObject> msg) -> msg.reply(new JsonObject().put("value", "Hello " + msg.body().getString("value"))));
    TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addInboundPermitted(new PermittedOptions()).addOutboundPermitted(new PermittedOptions()));
    bridge.listen(7000, res -> {
        context.assertTrue(res.succeeded());
        async.complete();
    });
}
Also used : Message(io.vertx.core.eventbus.Message) Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) BridgeOptions(io.vertx.ext.bridge.BridgeOptions) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) Before(org.junit.Before)

Aggregations

BridgeOptions (io.vertx.ext.bridge.BridgeOptions)5 PermittedOptions (io.vertx.ext.bridge.PermittedOptions)5 Message (io.vertx.core.eventbus.Message)4 JsonObject (io.vertx.core.json.JsonObject)4 Async (io.vertx.ext.unit.Async)3 Before (org.junit.Before)3 TcpEventBusBridge (io.vertx.ext.eventbus.bridge.tcp.TcpEventBusBridge)2 Vertx (io.vertx.core.Vertx)1 EventBus (io.vertx.core.eventbus.EventBus)1 Logger (io.vertx.core.logging.Logger)1 NetServerOptions (io.vertx.core.net.NetServerOptions)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1 X509Certificate (javax.security.cert.X509Certificate)1