@Override public void start() { ServiceDiscovery discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions() .setAnnounceAddress("service-announce") .setName("my-name")); Record record1 = new Record() .setType("eventbus-service-proxy") .setLocation(new JsonObject().put("endpoint", "the-service-address")) .setName("my-service") .setMetadata(new JsonObject().put("some-label", "some-value")); discovery.publish(record1, ar -> { if (ar.succeeded()) { System.out.println("\"" + record1.getName() + "\" successfully published!"); Record publishedRecord = ar.result(); } else { Record record2 = HttpEndpoint.createRecord("some-rest-api", "localhost", 8080, "/api"); discovery.publish(record2, ar -> { if (ar.succeeded()) { System.out.println("\"" + record2.getName() + "\" successfully published!"); Record publishedRecord = ar.result(); } else { discovery.unpublish(record1.getRegistration(), ar -> { if (ar.succeeded()) { System.out.println("\"" + record1.getName() + "\" successfully unpublished");
@Override public void start() { Router router = Router.router(vertx); router.get("/").handler(this::invoke); // Retrieve the service discovery ServiceDiscovery.create(vertx, discovery -> // Retrieve a web client HttpEndpoint.getWebClient(discovery, svc -> svc.getName().equals("vertx-greeting"), ar -> { if (ar.failed()) { System.out.println("D'oh the service is not available"); } else { client = ar.result(); vertx.createHttpServer().requestHandler(router).listen(8080); } })); }
/** * Creates a new instance of {@link ServiceDiscovery} using the default configuration. * * @param vertx the vert.x instance * @return the created instance */ static ServiceDiscovery create(Vertx vertx) { return create(vertx, new ServiceDiscoveryOptions()); }
public void unpublish(Record record, Handler<AsyncResult<Void>> handler) { serviceDiscovery.unpublish(record.getRegistration(), handler); }
/** * Closes the service discovery */ public void close() { delegate.close(); }
/** * Publishes a record. * @param record the record * @param resultHandler handler called when the operation has completed (successfully or not). In case of success, the passed record has a registration id required to modify and un-register the service. */ public void publish(Record record, Handler<AsyncResult<Record>> resultHandler) { delegate.publish(record, resultHandler); }
/** * Lookups for a set of records. Unlike {@link io.vertx.rxjava.servicediscovery.ServiceDiscovery#getRecord}, this method returns all matching * records. * @param filter the filter - see {@link io.vertx.rxjava.servicediscovery.ServiceDiscovery#getRecord} * @param resultHandler handler called when the lookup has been completed. When there are no matching record, the operation succeed, but the async result has an empty list as result. */ public void getRecords(JsonObject filter, Handler<AsyncResult<List<Record>>> resultHandler) { delegate.getRecords(filter, resultHandler); }
/** * Un-publishes a record. * @param id the registration id * @param resultHandler handler called when the operation has completed (successfully or not). */ public void unpublish(String id, Handler<AsyncResult<Void>> resultHandler) { delegate.unpublish(id, resultHandler); }
/** * Gets the object to access the service. It can be a proxy, a client or whatever object. The type depends on the * service type and the server itself. This method returns the Java version and primary facet of the object, use * {@link io.vertx.rxjava.servicediscovery.ServiceReference#getAs} to retrieve the polyglot instance of the object or another facet.. * @return the object to access the service */ public <T> T get() { T ret = (T) delegate.get(); return ret; }
/** * Releases the reference. Once released, the consumer must not use the reference anymore. * This method must be idempotent and defensive, as multiple call may happen. */ public void release() { delegate.release(); }
/** * Updates the given record. The record must has been published, and has it's registration id set. * @param record the updated record * @param resultHandler handler called when the lookup has been completed. */ public void update(Record record, Handler<AsyncResult<Record>> resultHandler) { delegate.update(record, resultHandler); }
/** * Gets the service object if already retrieved. It won't try to acquire the service object if not retrieved yet. * @return the object, <code>null</code> if not yet retrieved */ public <T> T cached() { T ret = (T) delegate.cached(); return ret; }
/** * Checks whether or not the service reference has the given service object. * @param object the service object, must not be <code>null</code> * @return <code>true</code> if the service reference service object is equal to the given object, <code>false</code> otherwise. */ public boolean isHolding(Object object) { boolean ret = delegate.isHolding(object); return ret; }
/** * @return the discovery options. Modifying the returned object would not update the discovery service configuration. This object should be considered as read-only. */ public ServiceDiscoveryOptions options() { ServiceDiscoveryOptions ret = delegate.options(); return ret; }
/** * @return the service record. */ public Record record() { if (cached_0 != null) { return cached_0; } Record ret = delegate.record(); cached_0 = ret; return ret; }
/** * Creates a new {@link Record} from its json representation. * * @param json the json object */ public Record(JsonObject json) { RecordConverter.fromJson(json, this); }
/** * Creates a new instance of {@link ServiceDiscoveryOptions} from its JSON representation. * * @param json the json object */ public ServiceDiscoveryOptions(JsonObject json) { this(); ServiceDiscoveryOptionsConverter.fromJson(json, this); }
/** * Creates a new instance of {@link ServiceDiscovery} using the default configuration. * * @param vertx the vert.x instance * @return the created instance */ static ServiceDiscovery create(Vertx vertx) { return create(vertx, new ServiceDiscoveryOptions()); }
/** * Releases the reference. Once released, the consumer must not use the reference anymore. * This method must be idempotent and defensive, as multiple call may happen. */ public void release() { delegate.release(); }
/** * Checks whether or not the service reference has the given service object. * @param object the service object, must not be <code>null</code> * @return <code>true</code> if the service reference service object is equal to the given object, <code>false</code> otherwise. */ public boolean isHolding(Object object) { boolean ret = delegate.isHolding(object); return ret; }