Search in sources :

Example 1 with PermittedOptions

use of io.vertx.ext.bridge.PermittedOptions 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 PermittedOptions

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

the class TcpEventBusBridgeImpl method checkMatches.

private boolean checkMatches(boolean inbound, String address, Map<String, Message<JsonObject>> replies) {
    // the replies registry
    if (replies != null && inbound && replies.containsKey(address)) {
        return true;
    }
    List<PermittedOptions> matches = inbound ? options.getInboundPermitteds() : options.getOutboundPermitteds();
    for (PermittedOptions matchHolder : matches) {
        String matchAddress = matchHolder.getAddress();
        String matchRegex;
        if (matchAddress == null) {
            matchRegex = matchHolder.getAddressRegex();
        } else {
            matchRegex = null;
        }
        boolean addressOK;
        if (matchAddress == null) {
            addressOK = matchRegex == null || regexMatches(matchRegex, address);
        } else {
            addressOK = matchAddress.equals(address);
        }
        if (addressOK) {
            return true;
        }
    }
    return false;
}
Also used : PermittedOptions(io.vertx.ext.bridge.PermittedOptions)

Example 3 with PermittedOptions

use of io.vertx.ext.bridge.PermittedOptions 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 4 with PermittedOptions

use of io.vertx.ext.bridge.PermittedOptions 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 5 with PermittedOptions

use of io.vertx.ext.bridge.PermittedOptions 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)

Aggregations

PermittedOptions (io.vertx.ext.bridge.PermittedOptions)6 BridgeOptions (io.vertx.ext.bridge.BridgeOptions)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