@Override public void start() throws Exception { // Use Factory method or just with constructor, either is OK someDatabaseService = SomeDatabaseService.create(); // Register your service to the address. new ServiceBinder(vertx.getDelegate()) .setAddress("proxy.address") .register(SomeDatabaseService.class, someDatabaseService); } }
@Override public void setUp() throws Exception { super.setUp(); OKService service = new OKServiceImpl(); final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress(SERVICE_ADDRESS); final ServiceBinder serviceLocalBinder = new ServiceBinder(vertx).setAddress(SERVICE_LOCAL_ADDRESS); final ServiceProxyBuilder serviceProxyBuilder = new ServiceProxyBuilder(vertx).setAddress(SERVICE_ADDRESS); final ServiceProxyBuilder serviceLocalProxyBuilder = new ServiceProxyBuilder(vertx).setAddress(SERVICE_LOCAL_ADDRESS); consumer = serviceBinder.register(OKService.class, service); localConsumer = serviceLocalBinder.registerLocal(OKService.class, service); proxy = serviceProxyBuilder.build(OKService.class); localProxy = serviceLocalProxyBuilder.build(OKService.class); }
public static <T> MessageConsumer<JsonObject> registerService(Class<T> clazz, Vertx vertx, T service, String address, long timeoutSeconds) { return new ServiceBinder(vertx) .setAddress(address) .setTimeoutSeconds(timeoutSeconds) .register(clazz, service); }
@Override public void stop() { serviceBinder.unregister(consumer); } }
public static <T> MessageConsumer<JsonObject> registerLocalService(Class<T> clazz, Vertx vertx, T service, String address, boolean topLevel, long timeoutSeconds) { return new ServiceBinder(vertx) .setAddress(address) .setTopLevel(topLevel) .setTimeoutSeconds(timeoutSeconds) .registerLocal(clazz, service); }
/** * Registers a local service on the event bus. * The registration will not be propagated to other nodes in the cluster. * * @param clazz the service class (interface) * @param vertx the vert.x instance * @param service the service object * @param address the address on which the service is published * @param <T> the type of the service interface * @return the consumer used to unregister the service */ public static <T> MessageConsumer<JsonObject> registerLocalService(Class<T> clazz, Vertx vertx, T service, String address) { return new ServiceBinder(vertx) .setAddress(address) .registerLocal(clazz, service); }
@Override public void setUp() throws Exception { super.setUp(); service = TestService.create(vertx); localService = TestService.create(vertx); consumer = new ServiceBinder(vertx).setAddress(SERVICE_ADDRESS) .register(TestService.class, service); localConsumer = new ServiceBinder(vertx).setAddress(SERVICE_LOCAL_ADDRESS) .registerLocal(TestService.class, localService); proxy = TestService.createProxy(vertx, SERVICE_ADDRESS); localProxy = TestService.createProxy(vertx, SERVICE_LOCAL_ADDRESS); vertx.eventBus().<String>consumer(TEST_ADDRESS).handler(msg -> { assertEquals("ok", msg.body()); testComplete(); }); }
public static <T> MessageConsumer<JsonObject> registerService(Class<T> clazz, Vertx vertx, T service, String address, boolean topLevel, long timeoutSeconds) { return new ServiceBinder(vertx) .setAddress(address) .setTopLevel(topLevel) .setTimeoutSeconds(timeoutSeconds) .register(clazz, service); }
@Override public void stop() { serviceBinder.unregister(consumer); } }
public static <T> MessageConsumer<JsonObject> registerLocalService(Class<T> clazz, Vertx vertx, T service, String address, long timeoutSeconds) { return new ServiceBinder(vertx) .setAddress(address) .setTimeoutSeconds(timeoutSeconds) .registerLocal(clazz, service); }
/** * Start transaction service */ private void startTransactionService() { serviceBinder = new ServiceBinder(vertx); TransactionPersistence persistence = TransactionPersistence.create(); // Create an instance of TransactionManagerService and mount to event bus TransactionsManagerService transactionsManagerService = TransactionsManagerService.create(persistence); consumer = serviceBinder .setAddress("transactions_manager.myapp") .register(TransactionsManagerService.class, transactionsManagerService); }
@Override public void setUp() throws Exception { super.setUp(); OKService service = new OKServiceImpl(); ServiceBinder serviceBinder = new ServiceBinder(vertx) .setAddress(SERVICE_ADDRESS) .addInterceptor(new ServiceJWTInterceptor().setJwtAuth(JWTAuth.create(vertx, new JWTAuthOptions() .addSecret(new SecretOptions() .setType("HS256") .setSecret("notasecret"))))); ServiceBinder localServiceBinder = new ServiceBinder(vertx) .setAddress(SERVICE_LOCAL_ADDRESS) .addInterceptor(new ServiceJWTInterceptor().setJwtAuth(JWTAuth.create(vertx, new JWTAuthOptions() .addSecret(new SecretOptions() .setType("HS256") .setSecret("notasecret"))))); consumer = serviceBinder.register(OKService.class, service); localConsumer = localServiceBinder.registerLocal(OKService.class, service); serviceProxyBuilder = new ServiceProxyBuilder(vertx) .setAddress(SERVICE_ADDRESS); localServiceProxyBuilder = new ServiceProxyBuilder(vertx) .setAddress(SERVICE_LOCAL_ADDRESS); }
@Override public void stop() throws Exception { serviceBinder.unregister(consumer); } }
@Override public void start() throws Exception { // Create the client object MyService service = new MyServiceImpl(); // Register the handler new ServiceBinder(vertx) .setAddress("proxy.example") .register(MyService.class, service); Router router = Router.router(vertx); BridgeOptions options = new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("proxy.example")); router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options)); // Serve the static resources router.route().handler(StaticHandler.create()); vertx.createHttpServer().requestHandler(router).listen(8080); } }
@Override public void stop() throws Exception { serviceBinder.unregister(consumer); } }
@Override public void start() throws Exception { // Create the client object ProcessorService service = new ProcessorServiceImpl(); // Register the handler new ServiceBinder(vertx) .setAddress("vertx.processor") .register(ProcessorService.class, service); Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("vertx.processor")) .addOutboundPermitted(new PermittedOptions().setAddress("vertx.processor")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); router.route().handler(StaticHandler.create()); // vertx.createHttpServer().requestHandler(router).listen(8080); }
@Override public void stop() throws Exception { serviceBinder.unregister(consumer); } }
/** * Registers a service on the event bus. * * @param clazz the service class (interface) * @param vertx the vert.x instance * @param service the service object * @param address the address on which the service is published * @param <T> the type of the service interface * @return the consumer used to unregister the service */ public static <T> MessageConsumer<JsonObject> registerService(Class<T> clazz, Vertx vertx, T service, String address) { return new ServiceBinder(vertx) .setAddress(address) .register(clazz, service); }
@Override public void stop() throws Exception { serviceBinder.unregister(consumer); } }
@Override public void start() throws Exception { LOGGER.info("Starting <{}>", this.getClass().getSimpleName()); //register the service proxy on event bus serviceBinder = new ServiceBinder(getVertx()); consumer = serviceBinder .setAddress(address) .register(RepositoryConnectorProxy.class, new FilesystemRepositoryConnectorProxyImpl(vertx, config())); }