当前位置: 首页>>代码示例>>Java>>正文


Java SockJSHandler.bridge方法代码示例

本文整理汇总了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;
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:20,代码来源:WebSocketConsumer.java

示例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);
}
 
开发者ID:mpusher,项目名称:mpns,代码行数:19,代码来源:AppServer.java

示例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);
    }
 
开发者ID:xmlking,项目名称:nifi-websocket,代码行数:23,代码来源:VertxService.java

示例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);


  }
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:26,代码来源:WebExamples.java

示例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);


  }
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:26,代码来源:WebExamples.java

示例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);
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:18,代码来源:WebExamples.java

示例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;
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:10,代码来源:WebServerVerticle.java

示例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;
}
 
开发者ID:GwtDomino,项目名称:domino-event-bus,代码行数:10,代码来源:VertxConfigSockJsConfigurator.java

示例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;
}
 
开发者ID:GwtDomino,项目名称:domino-event-bus,代码行数:12,代码来源:DefaultEventBusSockJsConfigurator.java

示例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);
  });
}
 
开发者ID:sczyh30,项目名称:vertx-blueprint-microservice,代码行数:38,代码来源:MonitorDashboardVerticle.java

示例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);

}
 
开发者ID:gentics,项目名称:mesh,代码行数:31,代码来源:EventbusEndpoint.java

示例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;

}
 
开发者ID:quebic-source,项目名称:puppy-io,代码行数:14,代码来源:ServerVerticle.java

示例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;
}
 
开发者ID:aesteve,项目名称:vertx-feeds,代码行数:9,代码来源:WebServer.java

示例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");
}
 
开发者ID:saffron-technology,项目名称:vertx-eventbusbridge,代码行数:37,代码来源:ExampleServer.java

示例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");
}
 
开发者ID:saffron-technology,项目名称:vertx-eventbusbridge,代码行数:38,代码来源:EventBusBridgeTest.java


注:本文中的io.vertx.ext.web.handler.sockjs.SockJSHandler.bridge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。