本文整理汇总了Java中io.vertx.servicediscovery.ServiceDiscovery.create方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceDiscovery.create方法的具体用法?Java ServiceDiscovery.create怎么用?Java ServiceDiscovery.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.servicediscovery.ServiceDiscovery
的用法示例。
在下文中一共展示了ServiceDiscovery.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.get("/shopping").handler(this::getList);
router.route().handler(BodyHandler.create());
router.post("/shopping").handler(this::addToList);
router.delete("/shopping/:name").handler(this::deleteFromList);
ServiceDiscovery.create(vertx, discovery -> {
RedisDataSource.getRedisClient(discovery, rec -> rec.getName().equals("redis"), ar -> {
redis = ar.result();
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
});
});
}
示例2: getServiceDiscovery
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
static ServiceDiscovery getServiceDiscovery(io.vertx.core.Vertx vertx) {
// Discovery settings
ServiceDiscoveryOptions serviceDiscoveryOptions = new ServiceDiscoveryOptions();
// Redis settings with the standard Redis Backend
Integer redisPort = Integer.parseInt(Optional.ofNullable(System.getenv("REDIS_PORT")).orElse("6379"));
String redisHost = Optional.ofNullable(System.getenv("REDIS_HOST")).orElse("127.0.0.1");
String redisAuth = Optional.ofNullable(System.getenv("REDIS_PASSWORD")).orElse(null);
String redisRecordsKey = Optional.ofNullable(System.getenv("REDIS_RECORDS_KEY")).orElse("vert.x.ms"); // the redis hash
return ServiceDiscovery.create(
vertx,
serviceDiscoveryOptions.setBackendConfiguration(
new JsonObject()
.put("host", redisHost)
.put("port", redisPort)
.put("auth", redisAuth)
.put("key", redisRecordsKey)
));
}
示例3: start
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@Override
public void start() {
Router router = Router.router(vertx);
router.get("/").handler(rc -> rc.response().end("hello "));
router.get("/shopping").handler(this::getList);
router.post().handler(BodyHandler.create());
router.post("/shopping").handler(this::addToList);
router.delete("/shopping/:name").handler(this::removeFromList);
ServiceDiscovery.create(vertx, discovery -> {
RedisDataSource.getRedisClient(discovery, svc -> svc.getName().equals("redis"), ar -> {
if (ar.failed()) {
System.out.println("D'oh");
} else {
redis = ar.result();
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}
});
});
}
开发者ID:cescoffier,项目名称:vertx-kubernetes-live-coding-devoxx-ma,代码行数:26,代码来源:ShoppingBackendVerticle.java
示例4: start
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@Override
public void start() {
Router router = Router.router(vertx);
router.get("/").handler(rc -> rc.response().end("Hello Austin"));
router.get("/shopping").handler(this::getList);
router.post().handler(BodyHandler.create());
router.post("/shopping").handler(this::addToList);
router.delete("/shopping/:name").handler(this::deleteFromList);
ServiceDiscovery.create(vertx, discovery -> {
RedisDataSource.getRedisClient(discovery, svc -> svc.getName().equals("redis"), ar -> {
if (ar.failed()) {
System.out.println("D'oh");
} else {
redis = ar.result();
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}
});
});
}
示例5: should_Manage_Registrations
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@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();
}
示例6: setUp
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@Before
public void setUp() {
init();
client = DockerClientBuilder.getInstance().build();
List<Container> running = client.listContainersCmd().withStatusFilter("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);
}
示例7: start
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@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))
);
}
示例8: setUp
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@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");
}
示例9: start
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
ServiceDiscovery.create(vertx, discovery -> {
RedisDataSource.getRedisClient(discovery, rec -> rec.getName().equals("redis"), ar -> {
if (ar.failed()) {
redis = RedisClient.create(vertx);
} else {
redis = ar.result();
}
router.get("/shopping").handler(this::getShoppingList);
router.route().handler(BodyHandler.create());
router.post("/shopping").handler(this::addItem);
router.get("/health").handler(rc -> rc.response().end("OK"));
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
});
});
}
示例10: start
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.get("/")
.handler(rc -> rc.response()
.end("Bonjour Tourcoing"));
router.get("/shopping").handler(this::getList);
router.route().handler(BodyHandler.create());
router.post("/shopping")
.handler(this::addToList);
router.delete("/shopping/:name").handler(this::deleteFromList);
ServiceDiscovery.create(vertx, discovery -> {
RedisDataSource.getRedisClient(discovery,
svc -> svc.getName().equals("redis"),
ar -> {
if (ar.failed()) {
System.out.println("D'oh !");
} else {
client = ar.result();
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}
});
});
}
示例11: start
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.get("/").handler(rc -> rc.response().end("Hello"));
router.get("/shopping").handler(this::getList);
router.route().handler(BodyHandler.create());
router.post("/shopping").handler(this::addToList);
router.delete("/shopping/:name").handler(this::removeFromList);
ServiceDiscovery.create(vertx, discovery -> {
RedisDataSource.getRedisClient(discovery,
svc -> svc.getName().equals("redis"),
ar -> {
if (ar.failed()) {
System.out.println("D'oh !");
} else {
client = ar.result();
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}
});
});
}
示例12: setUp
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
vertx = rule.vertx();
serviceDiscovery = ServiceDiscovery.create(vertx);
metadata = new JsonObject().put(KEY, VALUE);
jsonFilter = new JsonObject().put("name", SERVICE_NAME);
vertxServiceDiscovery = new VertxServiceDiscovery(vertx);
onSetup();
}
示例13: setUp
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@Before
public void setUp() {
service = UUID.randomUUID().toString();
vertx = Vertx.vertx();
discovery = ServiceDiscovery.create(vertx);
serviceFinder = ServiceFinder.create(vertx, discovery);
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
示例14: should_Cleanup_On_Close
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@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());
}
示例15: testSetup
import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
@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();
});
});
}