/** * Creates a record based on the parameters. * @param name the service name * @param address the address * @param classname the payload class * @return the record */ public static Record createRecord(String name, String address, String classname) { Record ret = io.vertx.servicediscovery.types.EventBusService.createRecord(name, address, classname); return ret; }
/** * Creates a record based on the parameters. * @param name the service name * @param address the address * @param classname the payload class * @return the record */ public static Record createRecord(String name, String address, String classname) { Record ret = io.vertx.servicediscovery.types.EventBusService.createRecord(name, address, classname); return ret; }
/** * Creates a record based on the parameters. * * @param name the service name * @param address the address * @param classname the payload class * @return the record */ static Record createRecord(String name, String address, String classname) { return createRecord(name, address, classname, null); } }
/** * Creates a record based on the parameters. * * @param name the service name * @param address the address * @param classname the payload class * @return the record */ static Record createRecord(String name, String address, String classname) { return createRecord(name, address, classname, null); } }
/** * Sugar method to creates a record for this type. * <p> * The java interface is added to the metadata in the `service.interface` key. * @param name the name of the service. * @param address the event bus address on which the service available * @param itf the Java interface (name) * @param metadata the metadata * @return the created record */ public static Record createRecord(String name, String address, String itf, JsonObject metadata) { Record ret = io.vertx.servicediscovery.types.EventBusService.createRecord(name, address, itf, metadata); return ret; }
/** * Sugar method to creates a record for this type. * <p> * The java interface is added to the metadata in the `service.interface` key. * @param name the name of the service. * @param address the event bus address on which the service available * @param itf the Java interface (name) * @param metadata the metadata * @return the created record */ public static Record createRecord(String name, String address, String itf, JsonObject metadata) { Record ret = io.vertx.servicediscovery.types.EventBusService.createRecord(name, address, itf, metadata); return ret; }
/** * Same as {@link #createRecord(String, String, Class, JsonObject)} but without metadata. * * @param name the name of the service * @param itf the Java interface * @param address the event bus address on which the service available * @return the created record */ @GenIgnore static Record createRecord(String name, String address, Class itf) { return createRecord(name, address, itf, null); }
public static java.util.Map<String, Object> createRecord(io.vertx.servicediscovery.types.EventBusService j_receiver, java.lang.String name, java.lang.String address, java.lang.String classname) { return io.vertx.servicediscovery.types.EventBusService.createRecord(name, address, classname) != null ? io.vertx.core.impl.ConversionHelper.fromJsonObject(io.vertx.servicediscovery.types.EventBusService.createRecord(name, address, classname).toJson()) : null; } }
public void publishEventBusService(String name, String address, Class<?> serviceClass, Handler<AsyncResult<Void>> completionHandler) { Record record = EventBusService.createRecord(name, address, serviceClass); publish(record, completionHandler); }
protected Future<Void> publishEventBusService(String name, String address, Class serviceClass) { Record record = EventBusService.createRecord(name, address, serviceClass); return publish(record); }
/** * Same as {@link #createRecord(String, String, Class, JsonObject)} but without metadata. * * @param name the name of the service * @param itf the Java interface * @param address the event bus address on which the service available * @return the created record */ @GenIgnore static Record createRecord(String name, String address, Class itf) { return createRecord(name, address, itf, null); }
protected Single<Void> publishEventBusService(String name, String address, Class serviceClass) { Record record = EventBusService.createRecord(name, address, serviceClass); return publish(record); }
/** * Sugar method to creates a record for this type. * <p> * The java interface is added to the metadata in the `service.interface` key. * * @param name the name of the service. * @param address the event bus address on which the service available * @param itf the Java interface * @param metadata the metadata * @return the created record */ @GenIgnore static Record createRecord(String name, String address, Class itf, JsonObject metadata) { return createRecord(name, address, itf.getName(), metadata); }
/** * Sugar method to creates a record for this type. * <p> * The java interface is added to the metadata in the `service.interface` key. * * @param name the name of the service. * @param address the event bus address on which the service available * @param itf the Java interface * @param metadata the metadata * @return the created record */ @GenIgnore static Record createRecord(String name, String address, Class itf, JsonObject metadata) { return createRecord(name, address, itf.getName(), metadata); }
public static java.util.Map<String, Object> createRecord(io.vertx.servicediscovery.types.EventBusService j_receiver, java.lang.String name, java.lang.String address, java.lang.String itf, java.util.Map<String, Object> metadata) { return io.vertx.servicediscovery.types.EventBusService.createRecord(name, address, itf, metadata != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(metadata) : null) != null ? io.vertx.core.impl.ConversionHelper.fromJsonObject(io.vertx.servicediscovery.types.EventBusService.createRecord(name, address, itf, metadata != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(metadata) : null).toJson()) : null; } public static <T>java.lang.Object getServiceProxy(io.vertx.servicediscovery.types.EventBusService j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.util.function.Function<java.util.Map<String, Object>, java.lang.Boolean> filter, java.lang.Class<java.lang.Object> clientClass, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Object>> resultHandler) {
private Record createEventBusRecord(EventBusServiceConfiguration configuration) { return EventBusService.createRecord(configuration.getName(), configuration.getAddress(), configuration.getServiceClass(), configuration.getMetadata()); }
@Test public void test() { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record = EventBusService.createRecord("Hello", "address", HelloService.class); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<Record> found = new AtomicReference<>(); discovery.getRecord(new JsonObject().put("name", "Hello"), ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); assertThat(found.get().getLocation().getString("endpoint")).isEqualTo("address"); ServiceReference service = discovery.getReference(found.get()); HelloService hello = service.get(); AtomicReference<String> result = new AtomicReference<>(); hello.hello(name, ar -> result.set(ar.result())); await().untilAtomic(result, not(nullValue())); service.release(); }
@Test public void testLookupWithNonMatchingQuery() throws UnsupportedEncodingException { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record1 = EventBusService.createRecord("Hello", "address", HelloService.class, new JsonObject().put("key", "foo")); Record record2 = EventBusService.createRecord("Hello-2", "address", HelloService.class, new JsonObject().put("key", "bar")); discovery.publish(record1, (r) -> { }); discovery.publish(record2, (r) -> { }); await().until(() -> record1.getRegistration() != null); await().until(() -> record2.getRegistration() != null); JsonArray services = given() .param("query", "{\"stuff\":\"*\"}") .get("/discovery") .asJsonArray(); assertThat(services.size()).isEqualTo(0); }
@Test public void testUsingGetMethod() { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record = EventBusService.createRecord("Hello", "address", HelloService.class); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<HelloService> found = new AtomicReference<>(); EventBusService.getProxy(discovery, HelloService.class, ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); Assertions.assertThat(discovery.bindings()).hasSize(1); HelloService hello = found.get(); AtomicReference<String> result = new AtomicReference<>(); hello.hello(name, ar -> result.set(ar.result())); await().untilAtomic(result, not(nullValue())); ServiceDiscovery.releaseServiceObject(discovery, found.get()); Assertions.assertThat(discovery.bindings()).hasSize(0); }
@Test public void testLookupWithQuery() throws UnsupportedEncodingException { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record1 = EventBusService.createRecord("Hello", "address", HelloService.class, new JsonObject().put("key", "foo")); Record record2 = EventBusService.createRecord("Hello-2", "address", HelloService.class, new JsonObject().put("key", "bar")); discovery.publish(record1, (r) -> { }); discovery.publish(record2, (r) -> { }); await().until(() -> record1.getRegistration() != null); await().until(() -> record2.getRegistration() != null); JsonArray services = given() .param("query", "{\"name\":\"Hello\"}") .get("/discovery") .asJsonArray(); assertThat(services.size()).isEqualTo(1); }