Skip to content

Instantly share code, notes, and snippets.

@ondrej-kvasnovsky
Created March 4, 2018 00:19
Show Gist options
  • Save ondrej-kvasnovsky/1b04317cc167ed16506ef9edb0736958 to your computer and use it in GitHub Desktop.
Save ondrej-kvasnovsky/1b04317cc167ed16506ef9edb0736958 to your computer and use it in GitHub Desktop.
package counter;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.shareddata.SharedData;
import io.vertx.ext.bridge.PermittedOptions;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.StaticHandler;
import io.vertx.ext.web.handler.sockjs.BridgeOptions;
import io.vertx.ext.web.handler.sockjs.SockJSHandler;
public class CounterVerticle extends AbstractVerticle {
@Override
public void start() {
Router router = Router.router(vertx);
router.route("/eventbus/*").handler(eventBusHandler());
router.route().handler(staticHandler());
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}
private SockJSHandler eventBusHandler() {
BridgeOptions options = new BridgeOptions()
.addOutboundPermitted(new PermittedOptions().setAddressRegex("out"))
.addInboundPermitted(new PermittedOptions().setAddressRegex("in"));
SharedData data = vertx.sharedData();
CounterRepository repository = new CounterRepository(data);
EventBus eventBus = vertx.eventBus();
CounterHandler counterHandler = new CounterHandler(eventBus, repository);
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
return sockJSHandler.bridge(options, counterHandler);
}
private StaticHandler staticHandler() {
return StaticHandler.create()
.setCachingEnabled(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment