2017-09-15 15 views

回答

0

不仅可以,那是通常的做法。

final Pattern chatUrlPattern = Pattern.compile("/ebus/(\\w+)"); 
    final EventBus eventBus = this.vertx.eventBus(); 

    final Router router = Router.router(this.vertx); 

    // Or wherever your static content is 
    router.route("web/*").handler(StaticHandler.create());   

    this.vertx.createHttpServer().websocketHandler(ws -> { 
     final Matcher m = chatUrlPattern.matcher(ws.path()); 
     if (!m.matches()) { 
      ws.reject(); 
      return; 
     } 
     /* Your code here */ 
    } 

    // Your Jersey code here, for example: 
    vertx.runOnContext(aVoid -> { 

     // Set up the jersey configuration 
     // The minimum config required is a package to inspect for JAX-RS endpoints 
     vertx.getOrCreateContext().config() 
       .put("jersey", new JsonObject() 
         .put("port", 8080) 
         .put("packages", new JsonArray() 
           .add(HelloWorldEndpoint.class.getPackage().getName()))); 

     // Use a service locator (HK2 or Guice are supported by default) to create the jersey server 
     ServiceLocator locator = ServiceLocatorUtilities.bind(new HK2JerseyBinder(), new HK2VertxBinder(vertx)); 
     JerseyServer server = locator.getService(JerseyServer.class); 

     // Start the server which simply returns "Hello World!" to each GET request. 
     server.start(); 

    }); 
+0

谢谢,我是用JerseyVerticle堆叠的,你指出我很好的方向。 –

相关问题