Search in sources :

Example 1 with TcpEventBusBridge

use of io.vertx.ext.eventbus.bridge.tcp.TcpEventBusBridge 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 TcpEventBusBridge

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

Aggregations

BridgeOptions (io.vertx.ext.bridge.BridgeOptions)2 PermittedOptions (io.vertx.ext.bridge.PermittedOptions)2 TcpEventBusBridge (io.vertx.ext.eventbus.bridge.tcp.TcpEventBusBridge)2 Vertx (io.vertx.core.Vertx)1 EventBus (io.vertx.core.eventbus.EventBus)1 Message (io.vertx.core.eventbus.Message)1 JsonObject (io.vertx.core.json.JsonObject)1