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"));
}
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();
});
}
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...
}
});
}
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();
});
}
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();
});
}
Aggregations