io.vertx.ext.web.handler.sockjs.PermittedOptions Java Examples

The following examples show how to use io.vertx.ext.web.handler.sockjs.PermittedOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WikiServer.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Override
protected void loadPlugins() {
	super.loadPlugins();
	plugins.add(new Plugin() {
		@Override
		public Completable preRoute() {
			return Completable.defer(() -> {
				AppGlobals globals = AppGlobals.get();

				SockJSHandler sockJSHandler = SockJSHandler.create(globals.getVertx());
				BridgeOptions bridgeOptions = new BridgeOptions()
						.addInboundPermitted(new PermittedOptions().setAddress("app.markdown"))
						.addOutboundPermitted(new PermittedOptions().setAddress("page.saved"));
				sockJSHandler.bridge(bridgeOptions);
				globals.getRouter().route("/eventbus/*").handler(sockJSHandler);

				return super.preRoute();
			});
		}
	});
}
 
Example #2
Source File: WikiServer.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Override
protected void loadPlugins() {
	super.loadPlugins();
	plugins.add(new Plugin() {
		@Override
		public Completable preRoute() {
			return Completable.defer(() -> {
				AppGlobals globals = AppGlobals.get();

				SockJSHandler sockJSHandler = SockJSHandler.create(globals.getVertx());
				BridgeOptions bridgeOptions = new BridgeOptions()
						.addInboundPermitted(new PermittedOptions().setAddress("app.markdown"))
						.addOutboundPermitted(new PermittedOptions().setAddress("page.saved"));
				sockJSHandler.bridge(bridgeOptions);
				globals.getRouter().route("/eventbus/*").handler(sockJSHandler);

				return super.preRoute();
			});
		}
	});
}
 
Example #3
Source File: AppServer.java    From mpns with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: MonitorDashboardVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 5 votes vote down vote up
@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);
  });
}
 
Example #5
Source File: DashboardVerticle.java    From vertx-kubernetes-workshop with Apache License 2.0 4 votes vote down vote up
@Override
public void start() throws Exception {

    Router router = Router.router(vertx);

    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    BridgeOptions options = new BridgeOptions();
    options
        .addOutboundPermitted(new PermittedOptions().setAddress("market"))
        .addOutboundPermitted(new PermittedOptions().setAddress("portfolio"))
        .addOutboundPermitted(new PermittedOptions().setAddress("service.portfolio"))
        .addInboundPermitted(new PermittedOptions().setAddress("service.portfolio"))
        .addOutboundPermitted(new PermittedOptions().setAddress("vertx.circuit-breaker"));

    sockJSHandler.bridge(options);
    router.route("/eventbus/*").handler(sockJSHandler);

    // Last operations
    router.get("/operations").handler(this::callAuditService);
    router.get("/health").handler(rc -> rc.response().end("OK"));


    MetricRegistry dropwizardRegistry = SharedMetricRegistries.getOrCreate(
        System.getProperty("vertx.metrics.options.registryName")
    );

    ServiceDiscovery.create(vertx, discovery -> {
        this.discovery = discovery;
        WebConsoleRegistry.create("/admin")
            // Add pages
            .addPage(MetricsConsolePage.create(dropwizardRegistry))
            .addPage(new TraderPage())
            .addPage(ServicesConsolePage.create(discovery))
            .addPage(CircuitBreakersConsolePage.create())
            .setCacheBusterEnabled(true) // Adds random query string to scripts
            // Mount to router
            .mount(vertx, router);

        retrieveAuditService();
        vertx.createHttpServer()
            .requestHandler(router::accept)
            .listen(8080);
    });

}
 
Example #6
Source File: DashboardVerticle.java    From microtrader with MIT License 4 votes vote down vote up
@Override
public void start(Future<Void> future) {
    // Get configuration
    config = ConfigFactory.load();

    discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setBackendConfiguration(config()));
    Router router = Router.router(vertx);

    // Event bus bridge
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    BridgeOptions options = new BridgeOptions();
    options
            .addOutboundPermitted(new PermittedOptions().setAddress(config.getString("market.address")))
            .addOutboundPermitted(new PermittedOptions().setAddress(config.getString("portfolio.address")))
            .addOutboundPermitted(new PermittedOptions().setAddress("service.portfolio"))
            .addInboundPermitted(new PermittedOptions().setAddress("service.portfolio"))
            .addOutboundPermitted(new PermittedOptions().setAddress("vertx.circuit-breaker"));

    sockJSHandler.bridge(options);
    router.route("/eventbus/*").handler(sockJSHandler);

    // Discovery endpoint
    ServiceDiscoveryRestEndpoint.create(router, discovery);

    // Last operations
    router.get("/operations").handler(this::callAuditServiceWithExceptionHandlerWithCircuitBreaker);

    // Static content
    router.route("/*").handler(StaticHandler.create());

    // Create a circuit breaker.
    circuit = CircuitBreaker.create("http-audit-service", vertx,
            new CircuitBreakerOptions()
                    .setMaxFailures(2)
                    .setFallbackOnFailure(true)
                    .setResetTimeout(2000)
                    .setTimeout(1000))
                    .openHandler(v -> retrieveAuditService());

    vertx.createHttpServer()
            .requestHandler(router::accept)
            .listen(config.getInt("http.port"), ar -> {
                if (ar.failed()) {
                    future.fail(ar.cause());
                } else {
                    retrieveAuditService();
                    future.complete();
                }
            });
}
 
Example #7
Source File: PubSubSockJsServer.java    From slime with MIT License 4 votes vote down vote up
@Override
  public void start() throws Exception{

	if( VertxHolder.getVertx() == null ) VertxHolder.setVertx(vertx);
	logger.info("Pub/Sub SockJs Server started on port {}", serverPort);
	
	Router router = Router.router(vertx);
	SockJSHandler socketHandler = SockJSHandler.create(vertx)
		.bridge(new BridgeOptions()
				.addOutboundPermitted(new PermittedOptions().setAddressRegex("^topic/.*"))
				
				// use to set client ping timeout -> will result closing connection if no ping sent
				/*.setPingTimeout(60000)*/,
				new Handler<BridgeEvent>() {
					@Override
					public void handle(BridgeEvent event) {
						boolean isResult = true;
						String message = "Oops!";
						
						System.out.println(event.type());
						
						EventBridgeChainResponse processInChain = eventBridgeChain.processInChain(event);
						if(processInChain.isProcesssed()) {
							if(processInChain.getException() != null) {
								isResult = false;
								logger.error(processInChain.getException().getMessage(), 
										processInChain.getException());
								message = processInChain.getException().getMessage();
							}
						}
						
					
						
						if(isResult) {
							
							if(event.type().equals(BridgeEventType.REGISTER)){
								System.out.println(event.getRawMessage());
								RedisSockjsClient.REGISTER(event);
							}
							
							
							event.complete(isResult);
						}
						else {
							event.fail(new Exception(message));
						}
						
					}
				});
	
	
	router.route("/sockjs/*").handler(
    	socketHandler
	);

	/*
	 * subscribe published message
	 */
	vertx.deployVerticle(new MessageSubscribeVerticle(), new DeploymentOptions().setWorker(true).setMultiThreaded(true));
	vertx.deployVerticle(new MessageSubscribeVerticle(), new DeploymentOptions().setWorker(true).setMultiThreaded(true));
	vertx.deployVerticle(new MessageSubscribeVerticle(), new DeploymentOptions().setWorker(true).setMultiThreaded(true));

    HttpServer server = vertx.createHttpServer().requestHandler(router::accept);
    
    
    server.listen(serverPort);

}
 
Example #8
Source File: DashboardVerticle.java    From vertx-microservices-workshop with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Future<Void> future) {
  super.start();
  Router router = Router.router(vertx);

  // Event bus bridge
  SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
  BridgeOptions options = new BridgeOptions();
  options
      .addOutboundPermitted(new PermittedOptions().setAddress("market"))
      .addOutboundPermitted(new PermittedOptions().setAddress("portfolio"))
      .addOutboundPermitted(new PermittedOptions().setAddress("service.portfolio"))
      .addInboundPermitted(new PermittedOptions().setAddress("service.portfolio"))
      .addOutboundPermitted(new PermittedOptions().setAddress("vertx.circuit-breaker"));

  sockJSHandler.bridge(options);
  router.route("/eventbus/*").handler(sockJSHandler);

  // Discovery endpoint
  ServiceDiscoveryRestEndpoint.create(router, discovery);

  // Last operations
  router.get("/operations").handler(this::callAuditServiceWithExceptionHandlerWithCircuitBreaker);

  // Static content
  router.route("/*").handler(StaticHandler.create());

  // Create a circuit breaker.
  circuit = CircuitBreaker.create("http-audit-service", vertx,
      new CircuitBreakerOptions()
          .setMaxFailures(2)
          .setFallbackOnFailure(true)
          .setResetTimeout(2000)
          .setTimeout(1000))
      .openHandler(v -> retrieveAuditService());

  vertx.createHttpServer()
      .requestHandler(router::accept)
      .listen(8080, ar -> {
        if (ar.failed()) {
          future.fail(ar.cause());
        } else {
          retrieveAuditService();
          future.complete();
        }
      });
}
 
Example #9
Source File: DashboardVerticle.java    From vertx-microservices-workshop with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Future<Void> future) {
  super.start();
  Router router = Router.router(vertx);

  // Event bus bridge
  SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
  BridgeOptions options = new BridgeOptions();
  options
      .addOutboundPermitted(new PermittedOptions().setAddress("market"))
      .addOutboundPermitted(new PermittedOptions().setAddress("portfolio"))
      .addOutboundPermitted(new PermittedOptions().setAddress("service.portfolio"))
      .addInboundPermitted(new PermittedOptions().setAddress("service.portfolio"))
      .addOutboundPermitted(new PermittedOptions().setAddress("vertx.circuit-breaker"));

  sockJSHandler.bridge(options);
  router.route("/eventbus/*").handler(sockJSHandler);

  // Discovery endpoint
  ServiceDiscoveryRestEndpoint.create(router, discovery);

  // Last operations
  router.get("/operations").handler(this::callAuditService);

  // Static content
  router.route("/*").handler(StaticHandler.create());

  // Create a circuit breaker.
  circuit = CircuitBreaker.create("http-audit-service", vertx,
      new CircuitBreakerOptions()
          .setMaxFailures(2)
          .setFallbackOnFailure(true)
          .setResetTimeout(2000)
          .setTimeout(1000))
      .openHandler(v -> retrieveAuditService());

  vertx.createHttpServer()
      .requestHandler(router::accept)
      .listen(8080, ar -> {
        if (ar.failed()) {
          future.fail(ar.cause());
        } else {
          retrieveAuditService();
          future.complete();
        }
      });
}