Java Code Examples for io.vertx.servicediscovery.ServiceDiscovery#create()
The following examples show how to use
io.vertx.servicediscovery.ServiceDiscovery#create() .
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: KubernetesServerTest.java From vertx-service-discovery with Apache License 2.0 | 6 votes |
/** * Reproduce issue https://github.com/vert-x3/vertx-service-discovery/issues/96. */ @Test public void testWatchWithDeletion() { AtomicBoolean done = new AtomicBoolean(); ServiceDiscovery discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setAutoRegistrationOfImporters(false)); discovery.registerServiceImporter(new KubernetesServiceImporter(), config().copy().put("namespace", "issue96"), ar -> done.set(ar.succeeded())); await().untilAtomic(done, is(true)); await().until(() -> { List<Record> records = getRecordsBlocking(discovery); try { assertThatListDoesNotContain(records, "hello-minikube"); return true; } catch (Throwable e) { return false; } }); }
Example 2
Source File: KubernetesServerTest.java From vertx-service-discovery with Apache License 2.0 | 6 votes |
@Test public void testInitialRetrieval(TestContext tc) { Async async = tc.async(); ServiceDiscovery discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setAutoRegistrationOfImporters(false)); discovery.registerServiceImporter(new KubernetesServiceImporter(), config().copy().put("namespace", "default"), ar -> { if (ar.failed()) { tc.fail(ar.cause()); } else { discovery.getRecords(s -> true, res -> { if (res.failed()) { tc.fail(res.cause()); } else { tc.assertEquals(2, res.result().size()); async.complete(); } }); } }); }
Example 3
Source File: BaseMicroserviceVerticle.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
@Override public void start() throws Exception { // init service discovery instance discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setBackendConfiguration(config())); // init circuit breaker instance JsonObject cbOptions = config().getJsonObject("circuit-breaker") != null ? config().getJsonObject("circuit-breaker") : new JsonObject(); circuitBreaker = CircuitBreaker.create(cbOptions.getString("name", "circuit-breaker"), vertx, new CircuitBreakerOptions() .setMaxFailures(cbOptions.getInteger("max-failures", 5)) .setTimeout(cbOptions.getLong("timeout", 10000L)) .setFallbackOnFailure(true) .setResetTimeout(cbOptions.getLong("reset-timeout", 30000L)) ); }
Example 4
Source File: DockerBridgeTest.java From vertx-service-discovery with Apache License 2.0 | 6 votes |
@Before public void setUp() { init(); client = DockerClientBuilder.getInstance().build(); List<Container> running = client.listContainersCmd().withStatusFilter(Collections.singletonList("running")).exec(); if (running != null) { running.forEach(container -> client.stopContainerCmd(container.getId()).exec()); } vertx = Vertx.vertx(); discovery = ServiceDiscovery.create(vertx); bridge = new DockerServiceImporter(); discovery.registerServiceImporter(bridge, new JsonObject().put("scan-period", -1)); await().until(() -> bridge.started); }
Example 5
Source File: AbstractRegistrarTest.java From vertx-graphql-service-discovery with Apache License 2.0 | 6 votes |
@Test public void should_Manage_Registrations() { abstractRegistrar.getOrCreateDiscovery(options, () -> { abstractRegistrar.closeServiceDiscovery(options.getName()); return null; }); TestRegistration registration1 = new TestRegistration(ServiceDiscovery.create(vertx, options), options); assertNotNull(abstractRegistrar.registrations()); abstractRegistrar.register(options.getName(), registration1); assertEquals(1, abstractRegistrar.registrations().size()); TestRegistration registration2 = new TestRegistration(ServiceDiscovery.create(vertx, options), options); abstractRegistrar.register(options.getName(), registration2); assertEquals(2, abstractRegistrar.registrations().size()); abstractRegistrar.unregister(registration2); assertEquals(1, abstractRegistrar.registrations().size()); assertEquals(1, abstractRegistrar.serviceDiscoveryNames().size()); abstractRegistrar.unregister(registration1); assertEquals(0, abstractRegistrar.registrations().size()); assertEquals(0, abstractRegistrar.serviceDiscoveryNames().size()); abstractRegistrar.close(); }
Example 6
Source File: SchemaRegistrationTest.java From vertx-graphql-service-discovery with Apache License 2.0 | 6 votes |
@Before public void setUp() { vertx = Vertx.vertx(); options = new ServiceDiscoveryOptions().setName("theDiscovery") .setAnnounceAddress("theAnnounceAddress").setUsageAddress("theUsageAddress"); discovery = ServiceDiscovery.create(vertx, options); record = new Record() .setName("theRecord") .setType(Queryable.SERVICE_TYPE) .setMetadata(new JsonObject().put("publisherId", "thePublisherId")) .setLocation(new JsonObject().put(Record.ENDPOINT, Queryable.ADDRESS_PREFIX + ".DroidQueries")) .setStatus(Status.UP); definition = SchemaDefinition.createInstance(droidsSchema, SchemaMetadata.create(new JsonObject().put("publisherId", "thePublisherId"))); consumer = ProxyHelper.registerService(Queryable.class, vertx, definition, Queryable.ADDRESS_PREFIX + ".DroidQueries"); }
Example 7
Source File: ConsulServiceImporterTest.java From vertx-service-discovery with Apache License 2.0 | 6 votes |
@Test public void testHttpImport() { services.add(buildService("172.17.0.2", "web", "web", new String[]{"rails", "http-endpoint"}, 80, "passing")); discovery = ServiceDiscovery.create(vertx); discovery.registerServiceImporter(new ConsulServiceImporter(), new JsonObject().put("host", "localhost").put("port", 5601)); await().until(() -> getAllRecordsBlocking().size() > 0); List<Record> list = getAllRecordsBlocking(); assertThat(list).hasSize(1); assertThat(list.get(0).getType()).isEqualTo(HttpEndpoint.TYPE); assertThat(list.get(0).getLocation().getString("endpoint")).isEqualTo("http://172.17.0.2:80"); }
Example 8
Source File: ServiceDiscoveryBackendZookeeperExamples.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
public void configuration1(Vertx vertx) { ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions() .setBackendConfiguration( new JsonObject() .put("connection", "127.0.0.1:2181") )); }
Example 9
Source File: DockerLinksServiceImporterTest.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
@Test public void testImport() throws InterruptedException { Vertx vertx = Vertx.vertx(); ServiceDiscovery service = ServiceDiscovery.create(vertx); service.registerServiceImporter(new DockerLinksServiceImporter(), new JsonObject()); List<Record> records = new ArrayList<>(); vertx.setPeriodic(100, l -> { if (records.size() >= 2) { vertx.cancelTimer(l); } else { service.getRecords(new JsonObject(), ar -> { records.clear(); records.addAll(ar.result()); }); } }); await().until(() -> records.size() == 2); for (Record record : records) { switch (record.getName()) { case "CONSOLIDATION": assertConsolidation(record); break; case "DISCOVERY_REDIS": assertRedis(record); break; default: fail("Unexpected record name"); break; } } }
Example 10
Source File: DiscoveryRegistrationTest.java From vertx-graphql-service-discovery with Apache License 2.0 | 5 votes |
@Before public void setUp() { vertx = Vertx.vertx(); options = new ServiceDiscoveryOptions().setName("theDiscovery") .setAnnounceAddress("foo").setUsageAddress("bar"); options2 = new ServiceDiscoveryOptions().setName("theDiscovery2") .setAnnounceAddress("foo").setUsageAddress("bar"); discovery = ServiceDiscovery.create(vertx, options); discovery2 = ServiceDiscovery.create(vertx, options); }
Example 11
Source File: AbstractRegistrarTest.java From vertx-graphql-service-discovery with Apache License 2.0 | 5 votes |
@Test public void should_Cleanup_On_Close() { abstractRegistrar.getOrCreateDiscovery(options, () -> { abstractRegistrar.closeServiceDiscovery(options.getName()); return null; }); TestRegistration registration1 = new TestRegistration(ServiceDiscovery.create(vertx, options), options); abstractRegistrar.register(options.getName(), registration1); assertEquals(1, abstractRegistrar.registrations().size()); assertEquals(1, abstractRegistrar.serviceDiscoveryNames().size()); abstractRegistrar.close(); assertEquals(0, abstractRegistrar.registrations().size()); assertEquals(0, abstractRegistrar.serviceDiscoveryNames().size()); }
Example 12
Source File: ConsulServiceImporterTest.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
@Test public void testAServiceBeingTwiceInConsul() { services.add(buildService("10.4.7.221", "ubuntu221:mysql:3306", "db", new String[] {"master", "backups"}, 32769, "passing")); services.add(buildService("10.4.7.220", "ubuntu220:mysql:3306", "db", new String[] {"master", "backups"}, 32771, "passing")); discovery = ServiceDiscovery.create(vertx); discovery.registerServiceImporter(new ConsulServiceImporter(), new JsonObject().put("host", "localhost").put("port", 5601)); await().until(() -> getAllRecordsBlocking().size() > 0); List<Record> list = getAllRecordsBlocking(); assertThat(list).hasSize(2); }
Example 13
Source File: ServiceDiscoveryBackendConsulExamples.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
public void configuration1(Vertx vertx) { ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions() .setBackendConfiguration( new JsonObject() .put("defaultHost", "127.0.0.1") .put("dc", "my-dc") )); }
Example 14
Source File: PortfolioServiceSellTest.java From microtrader with MIT License | 5 votes |
@Before public void testSetup(TestContext context) { Async async = context.async(); vertx = Vertx.vertx(); discovery = ServiceDiscovery .create(vertx, new ServiceDiscoveryOptions() .setBackendConfiguration(vertx.getOrCreateContext().config())); svc = new PortfolioServiceImpl(vertx, discovery, 10000); svc.getPortfolio(ar -> { portfolio = ar.result(); svc.buy(3, getQuote(), result -> { async.complete(); }); }); }
Example 15
Source File: AbstractRegistrationTest.java From vertx-graphql-service-discovery with Apache License 2.0 | 5 votes |
@Test public void should_Implement_Proper_Reference_Equality() { TestRegistration registration1 = new TestRegistration(discovery, options); assertEquals(registration1, registration1); assertNotEquals(registration1, "test"); TestRegistration registration2 = new TestRegistration(discovery, options); assertEquals(registration1, registration2); assertEquals(registration1.getDiscovery(), registration2.getDiscovery()); assertEquals(registration1.getDiscoveryOptions().getName(), registration2.getDiscoveryOptions().getName()); assertNotEquals(registration1.getDiscoveryOptions(), registration2.getDiscoveryOptions()); // returns a copy TestRegistration registration3 = new TestRegistration(discovery, new ServiceDiscoveryOptions(options)); assertEquals(registration1, registration3); TestRegistration registration4 = new TestRegistration(discovery, new ServiceDiscoveryOptions(options).setName("theOtherDiscovery")); assertNotEquals(registration1, registration4); TestRegistration registration5 = new TestRegistration(ServiceDiscovery.create(vertx), options); assertNotEquals(registration1, registration5); // would be illegal as well }
Example 16
Source File: GraphQLServiceImplTest.java From vertx-graphql-service-discovery with Apache License 2.0 | 5 votes |
@Before public void setUp() { vertx = Vertx.vertx(); discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setName("test-discovery")); config = new JsonObject().put("deliveryOptions", new JsonObject().put("timeout", 1000).put("codecName", "theCodecName")); record = new Record().setLocation(new JsonObject().put(Record.ENDPOINT, "theEndpoint")); graphQLService = new io.engagingspaces.graphql.servicediscovery.service.impl.GraphQLServiceImpl(); }
Example 17
Source File: ServiceDiscoveryExamples.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
public void example1(Vertx vertx) { // Use default configuration ServiceDiscovery discovery = ServiceDiscovery.create(vertx); // Customize the configuration discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions() .setAnnounceAddress("service-announce") .setName("my-name")); // Do something... discovery.close(); }
Example 18
Source File: GraphQLServiceTest.java From vertx-graphql-service-discovery with Apache License 2.0 | 4 votes |
@Before public void setUp() { vertx = Vertx.vertx(); options = new ServiceDiscoveryOptions().setName("my-schema-discovery"); discovery = ServiceDiscovery.create(vertx, options); }
Example 19
Source File: MicroserviceVerticle.java From microtrader with MIT License | 4 votes |
@Override public void start() { discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setBackendConfiguration(config())); }
Example 20
Source File: CallbackTraderVerticle.java From vertx-kubernetes-workshop with Apache License 2.0 | 4 votes |
private Future<ServiceDiscovery> getServiceDiscovery(Vertx vertx) { Future<ServiceDiscovery> future = Future.future(); ServiceDiscovery.create(vertx, future::complete); return future; }