Java Code Examples for io.vertx.servicediscovery.types.EventBusService#createRecord()
The following examples show how to use
io.vertx.servicediscovery.types.EventBusService#createRecord() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceDiscoveryRestEndpointTest.java From vertx-service-discovery with Apache License 2.0 | 6 votes |
@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); }
Example 2
Source File: EventBusServiceJavaExamples.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
public void example1(ServiceDiscovery discovery) { Record record = EventBusService.createRecord( "some-eventbus-service", // The service name "address", // the service address, MyService.class // the service interface ); discovery.publish(record, ar -> { // ... }); }
Example 3
Source File: EventBusServiceExamples.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
public void example1(ServiceDiscovery discovery) { Record record = EventBusService.createRecord( "some-eventbus-service", // The service name "address", // the service address, "examples.MyService", // the service interface as string new JsonObject() .put("some-metadata", "some value") ); discovery.publish(record, ar -> { // ... }); }
Example 4
Source File: ServiceDiscoveryRestEndpointTest.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
@Test public void testThatWeGetTheTwoPublishedServicesWithMetadata() { 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); Restafari.Response response = get("/discovery"); JsonArray services = new JsonArray(response.asString()); assertThat(services.size()).isEqualTo(2); for (Object json : services) { Record rec = new Record((JsonObject) json); assertThat(rec.getStatus()).isEqualTo(Status.UP); assertThat(rec.getRegistration()).isNotNull(); assertThat(rec.getName()).startsWith("Hello"); assertThat(rec.getMetadata().getString("key")).isNotNull(); get("/discovery/" + rec.getRegistration()).then().body("name", not(nullValue())); } }
Example 5
Source File: ServiceDiscoveryRestEndpointTest.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
@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); }
Example 6
Source File: ServiceProxiesTest.java From vertx-lang-groovy with Apache License 2.0 | 5 votes |
@Test public void testWithGroovyConsumer() { // Step 1 - register the service 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); // Step 2 - register a consumer that get the result AtomicReference<JsonObject> result = new AtomicReference<>(); vertx.eventBus().<JsonObject>consumer("result", message -> result.set(message.body())); // Step 3 - deploy the verticle vertx.deployVerticle("discovery/verticles/HelloServiceConsumer.groovy", ar -> { if (ar.failed()) { // Will fail anyway. ar.cause().printStackTrace(); } }); await().until(() -> result.get() != null); assertThat(result.get().getString("status")).isEqualTo("ok"); assertThat(result.get().getString("message")).isEqualTo("stuff vert.x"); }
Example 7
Source File: ServiceProxiesTest.java From vertx-lang-groovy with Apache License 2.0 | 5 votes |
@Test public void testWithGroovyConsumerWithJsonFilter() { // Step 1 - register the service 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); // Step 2 - register a consumer that get the result AtomicReference<JsonObject> result = new AtomicReference<>(); vertx.eventBus().<JsonObject>consumer("result", message -> result.set(message.body())); // Step 3 - deploy the verticle vertx.deployVerticle("discovery/verticles/HelloServiceConsumerWithJsonFilter.groovy", ar -> { if (ar.failed()) { // Will fail anyway. ar.cause().printStackTrace(); } }); await().until(() -> result.get() != null); assertThat(result.get().getString("status")).isEqualTo("ok"); assertThat(result.get().getString("message")).isEqualTo("stuff vert.x"); }
Example 8
Source File: MicroserviceVerticle.java From microtrader with MIT License | 4 votes |
public void publishEventBusService(String name, String address, Class serviceClass, Handler<AsyncResult<Void>> completionHandler) { Record record = EventBusService.createRecord(name, address, serviceClass); publish(record, completionHandler); }
Example 9
Source File: BaseMicroserviceVerticle.java From vertx-blueprint-microservice with Apache License 2.0 | 4 votes |
protected Future<Void> publishEventBusService(String name, String address, Class serviceClass) { Record record = EventBusService.createRecord(name, address, serviceClass); return publish(record); }
Example 10
Source File: BaseMicroserviceRxVerticle.java From vertx-blueprint-microservice with Apache License 2.0 | 4 votes |
protected Single<Void> publishEventBusService(String name, String address, Class serviceClass) { Record record = EventBusService.createRecord(name, address, serviceClass); return publish(record); }
Example 11
Source File: MicroServiceVerticle.java From vertx-microservices-workshop with Apache License 2.0 | 4 votes |
public void publishEventBusService(String name, String address, Class<?> serviceClass, Handler<AsyncResult<Void>> completionHandler) { Record record = EventBusService.createRecord(name, address, serviceClass); publish(record, completionHandler); }