本文整理汇总了Java中io.vertx.ext.web.handler.sockjs.SockJSHandler.bridge方法的典型用法代码示例。如果您正苦于以下问题:Java SockJSHandler.bridge方法的具体用法?Java SockJSHandler.bridge怎么用?Java SockJSHandler.bridge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.web.handler.sockjs.SockJSHandler
的用法示例。
在下文中一共展示了SockJSHandler.bridge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addRoutes
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
@Override
public SFDCRouterExtension addRoutes(final Router router) {
// Socket handler
final SockJSHandlerOptions options = new SockJSHandlerOptions().setHeartbeatInterval(2000);
final SockJSHandler sockJSHandler = SockJSHandler.create(this.vertx, options);
final BridgeOptions bo = new BridgeOptions()
.addOutboundPermitted(new PermittedOptions().setAddress(this.getWebSocketName()));
sockJSHandler.bridge(bo, event -> {
this.logger.info("A websocket event occurred: " + event.type() + "; " + event.getRawMessage());
event.complete(true);
});
final String someURL = this.getConsumerConfig().getUrl();
this.logger.info("Router listening on " + someURL + " for " + this.getWebSocketName());
router.route(someURL).handler(sockJSHandler);
return this;
}
示例2: initWebSocket
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
private void initWebSocket() {
Router router = Router.router(vertx);
SockJSHandlerOptions options = new SockJSHandlerOptions()
.setHeartbeatInterval(1000 * 60);
SockJSHandler sockJSHandler = SockJSHandler.create(vertx, options);
PermittedOptions inboundPermitted = new PermittedOptions().setAddressRegex("server/.*");
PermittedOptions outboundPermitted = new PermittedOptions().setAddressRegex("client/.*");
BridgeOptions ops = new BridgeOptions()
.addInboundPermitted(inboundPermitted)
.addOutboundPermitted(outboundPermitted);
sockJSHandler.bridge(ops);
router.route("/eb/*").handler(sockJSHandler);
mainRouter.mountSubRouter("/ws", router);
}
示例3: createSockJSServer
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
private void createSockJSServer(final ConfigurationContext context) throws InitializationException {
final int port = context.getProperty(PORT).asInteger();
final String ContextPath = context.getProperty(CONTEXT_PATH).getValue();
Router router = Router.router(vertx);
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
if (context.getProperty(INBOUND_ADDRESS_REGEX).isSet()) {
options.addInboundPermitted(new PermittedOptions().setAddressRegex(context.getProperty(INBOUND_ADDRESS_REGEX).getValue()));
}
if (context.getProperty(OUTBOUND_ADDRESS_REGEX).isSet()) {
options.addOutboundPermitted(new PermittedOptions().setAddressRegex(context.getProperty(OUTBOUND_ADDRESS_REGEX).getValue()));
}
sockJSHandler.bridge(options);
router.route(ContextPath).handler(sockJSHandler);
httpServer = vertx.createHttpServer().requestHandler(router::accept).listen(port);
}
示例4: example48_1
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
public void example48_1(Vertx vertx) {
Router router = Router.router(vertx);
// Let through any messages sent to 'demo.orderService' from the client
PermittedOptions inboundPermitted = new PermittedOptions().setAddress("demo.orderService");
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions().addInboundPermitted(inboundPermitted);
sockJSHandler.bridge(options, be -> {
if (be.type() == BridgeEventType.PUBLISH || be.type() == BridgeEventType.SEND) {
// Add some headers
JsonObject headers = new JsonObject().put("header1", "val").put("header2", "val2");
JsonObject rawMessage = be.getRawMessage();
rawMessage.put("headers", headers);
be.setRawMessage(rawMessage);
}
be.complete(true);
});
router.route("/eventbus/*").handler(sockJSHandler);
}
示例5: example49
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
public void example49(Vertx vertx) {
Router router = Router.router(vertx);
// Let through any messages sent to 'demo.orderMgr' from the client
PermittedOptions inboundPermitted = new PermittedOptions().setAddress("demo.someService");
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions().addInboundPermitted(inboundPermitted);
sockJSHandler.bridge(options, be -> {
if (be.type() == BridgeEventType.PUBLISH || be.type() == BridgeEventType.RECEIVE) {
if (be.getRawMessage().getString("body").equals("armadillos")) {
// Reject it
be.complete(false);
return;
}
}
be.complete(true);
});
router.route("/eventbus/*").handler(sockJSHandler);
}
示例6: handleSocketIdle
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
public void handleSocketIdle(Vertx vertx, PermittedOptions inboundPermitted) {
Router router = Router.router(vertx);
// Initialize SockJS handler
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions().addInboundPermitted(inboundPermitted).setPingTimeout(5000);
sockJSHandler.bridge(options, be -> {
if (be.type() == BridgeEventType.SOCKET_IDLE) {
// Do some custom handling...
}
be.complete(true);
});
router.route("/eventbus/*").handler(sockJSHandler);
}
示例7: eventBusHandler
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
private SockJSHandler eventBusHandler() {
SockJSHandler handler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
// open access
PermittedOptions permitted = new PermittedOptions();
options.addOutboundPermitted(permitted);
handler.bridge(options);
return handler;
}
示例8: configureSockJsHandler
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
private SockJSHandler configureSockJsHandler(VertxContext vertxContext, BridgeOptions bridgeOptions,
JsonObject config) {
SockJSHandler sockJSHandler = SockJSHandler.create(vertxContext.vertx());
sockJSHandler.bridge(bridgeOptions, event -> event.complete(true));
JsonArray jsonArray=config.getJsonArray(ALLOWED_ORIGINS, new JsonArray().add("*"));
sockJSHandler.socketHandler(event -> jsonArray.forEach(o -> event.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, (String)o)));
return sockJSHandler;
}
示例9: configure
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
@Override
public SockJSHandler configure(VertxContext vertxContext, ServerConfiguration<JsonObject, JsonObject[]> config) {
BridgeOptions bridgeOptions=new BridgeOptions();
bridgeOptions.addOutboundPermitted(new PermittedOptions().setAddress(VertxBusContext.DEFAULT_SOCKJS_ADDRESS));
SockJSHandler sockJSHandler = SockJSHandler.create(vertxContext.vertx());
sockJSHandler.bridge(bridgeOptions, event -> event.complete(true));
sockJSHandler.socketHandler(event -> event.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, ALLOW_ALL));
return sockJSHandler;
}
示例10: start
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
super.start();
Router router = Router.router(vertx);
// create Dropwizard metrics service
MetricsService service = MetricsService.create(vertx);
// event bus bridge
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions()
.addOutboundPermitted(new PermittedOptions().setAddress("microservice.monitor.metrics"))
.addOutboundPermitted(new PermittedOptions().setAddress("events.log"));
sockJSHandler.bridge(options);
router.route("/eventbus/*").handler(sockJSHandler);
// discovery endpoint
ServiceDiscoveryRestEndpoint.create(router, discovery);
// static content
router.route("/*").handler(StaticHandler.create());
int port = config().getInteger("monitor.http.port", 9100);
String host = config().getString("monitor.http.host", "0.0.0.0");
int metricsInterval = config().getInteger("monitor.metrics.interval", 5000);
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(port, host);
// send metrics message to the event bus
vertx.setPeriodic(metricsInterval, t -> {
JsonObject metrics = service.getMetricsSnapshot(vertx);
vertx.eventBus().publish("microservice.monitor.metrics", metrics);
});
}
示例11: addEventBusHandler
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
private void addEventBusHandler() {
SockJSHandler handler = null;
if (localRouter != null) {
SockJSHandlerOptions sockJSoptions = new SockJSHandlerOptions().setHeartbeatInterval(2000);
handler = SockJSHandler.create(Mesh.vertx(), sockJSoptions);
BridgeOptions bridgeOptions = new BridgeOptions();
for (String addr : Events.publicEvents()) {
bridgeOptions.addInboundPermitted(new PermittedOptions().setAddress(addr));
bridgeOptions.addOutboundPermitted(new PermittedOptions().setAddress(addr));
}
handler.bridge(bridgeOptions, event -> {
if (log.isDebugEnabled()) {
if (event.type() == BridgeEventType.SOCKET_CREATED) {
log.debug("A websocket was created");
}
}
// Only grant access to authenticated users
User user = event.socket().webUser();
boolean isAuthenticated = user != null;
event.complete(isAuthenticated);
});
}
secureAll();
EndpointRoute endpoint = createEndpoint();
endpoint.setRAMLPath("/");
endpoint.description("This endpoint provides a sockjs complient websocket which can be used to interface with the vert.x eventbus.");
endpoint.path("/*").handler(handler);
}
示例12: socketJSRegister
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
private SockJSHandler socketJSRegister() {
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
//[appName].[address]
options.addOutboundPermitted(new PermittedOptions().setAddressRegex(appConfig.getAppName() + "..*"));
sockJSHandler.bridge(options, event -> {
if (event.type() == BridgeEventType.SOCKET_CREATED) {
}
event.complete(true);
});
return sockJSHandler;
}
示例13: eventBusHandler
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
private SockJSHandler eventBusHandler() {
SockJSHandler handler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
PermittedOptions permitted = new PermittedOptions(); /* allow everything, we don't care for the demo */
options.addOutboundPermitted(permitted);
handler.bridge(options);
return handler;
}
示例14: createServer
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
public void createServer() throws InterruptedException {
vertx = Vertx.vertx();
CountDownLatch latch = new CountDownLatch(1);
Router router = Router.router(vertx);
// events specific to THOPs are made available over the bridge
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
options.addOutboundPermitted(new PermittedOptions().setAddress("test")).
addInboundPermitted(new PermittedOptions().setAddress("test")).
addOutboundPermitted(new PermittedOptions().setAddress("end")).
addInboundPermitted(new PermittedOptions().setAddress("end")).
addInboundPermitted(new PermittedOptions().setAddress("reply")).
addOutboundPermitted(new PermittedOptions().setAddress("replyTest"));
sockJSHandler.bridge(options);
router.route("/bridge/*").handler(sockJSHandler);
// for reply test
vertx.eventBus().consumer("reply", msg -> {
vertx.eventBus().send("replyTest", "replyToMe", reply -> {
assertEquals("bubu", reply.result().body().toString());
reply.result().reply("ok", replyOfreply -> {
assertEquals("roger", replyOfreply.result().body().toString());
});
msg.reply("ok");
vertx.eventBus().send("test", "ok");
});
});
vertx.createHttpServer().requestHandler(router::accept).listen(8765, (res) -> {
latch.countDown();
});
latch.await();
System.out.println("Server listening on port 8765");
}
示例15: createServer
import io.vertx.ext.web.handler.sockjs.SockJSHandler; //导入方法依赖的package包/类
@BeforeClass
public static void createServer() throws InterruptedException {
vertx = Vertx.vertx();
CountDownLatch latch = new CountDownLatch(1);
Router router = Router.router(vertx);
// events specific to THOPs are made available over the bridge
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
options.addOutboundPermitted(new PermittedOptions().setAddress("test")).
addInboundPermitted(new PermittedOptions().setAddress("test")).
addOutboundPermitted(new PermittedOptions().setAddress("end")).
addInboundPermitted(new PermittedOptions().setAddress("end")).
addInboundPermitted(new PermittedOptions().setAddress("reply")).
addOutboundPermitted(new PermittedOptions().setAddress("replyTest"));
sockJSHandler.bridge(options);
router.route("/bridge/*").handler(sockJSHandler);
// for reply test
vertx.eventBus().consumer("reply", msg -> {
vertx.eventBus().send("replyTest", "replyToMe", reply -> {
assertEquals("bubu", reply.result().body().toString());
reply.result().reply("ok", replyOfreply -> {
assertEquals("roger", replyOfreply.result().body().toString());
});
msg.reply("ok");
vertx.eventBus().send("test", "ok");
});
});
vertx.createHttpServer().requestHandler(router::accept).listen(8765, (res) -> {
latch.countDown();
});
latch.await();
System.out.println("Server listening on port 8765");
}