本文整理汇总了Java中io.vertx.servicediscovery.ServiceDiscoveryOptions类的典型用法代码示例。如果您正苦于以下问题:Java ServiceDiscoveryOptions类的具体用法?Java ServiceDiscoveryOptions怎么用?Java ServiceDiscoveryOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceDiscoveryOptions类属于io.vertx.servicediscovery包,在下文中一共展示了ServiceDiscoveryOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getServiceDiscovery
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的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)
));
}
示例2: testInitialRetrieval
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的package包/类
@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();
}
});
}
});
}
示例3: setUp
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的package包/类
@Before
public void setUp() {
vertx = Vertx.vertx();
discovery = new DiscoveryImpl(vertx, new ServiceDiscoveryOptions());
Router router = Router.router(vertx);
router.get("/foo").handler(ctxt -> {
ctxt.response().end("hello");
});
AtomicBoolean done = new AtomicBoolean();
vertx.createHttpServer().requestHandler(router::accept).listen(8080, ar -> {
done.set(ar.succeeded());
});
await().untilAtomic(done, is(true));
}
示例4: start
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的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))
);
}
示例5: should_Cleanup_Unused_Consumers_On_Closing_Managed_Discovery
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的package包/类
@Test
public void should_Cleanup_Unused_Consumers_On_Closing_Managed_Discovery() {
discoveryRegistrar = DiscoveryRegistrar.create(vertx);
ServiceDiscovery discovery1 = discoveryRegistrar.startListening(
new ServiceDiscoveryOptions().setName("discovery1"), record -> {}, refData -> {}).getDiscovery();
ServiceDiscovery discovery2 = discoveryRegistrar.startListening(
new ServiceDiscoveryOptions().setName("discovery1"), record -> {}, refData -> {}).getDiscovery();
ServiceDiscovery discovery3 = discoveryRegistrar.startListening(
new ServiceDiscoveryOptions().setName("discovery2").setAnnounceAddress("otherAnnounce"),
record -> {}, refData -> {}).getDiscovery();
assertEquals(2, discoveryRegistrar.serviceDiscoveryNames().size());
assertNotNull(discoveryRegistrar.getDiscovery("discovery1"));
assertEquals(discoveryRegistrar.getDiscovery("discovery1"), discovery2);
assertNotEquals(discoveryRegistrar.getDiscovery("discovery2"), discoveryRegistrar.getDiscovery("discovery3"));
// TODO Complete test
discovery1.close();
}
示例6: should_Stop_Repository_Listening_And_Remove_Registration
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的package包/类
@Test
public void should_Stop_Repository_Listening_And_Remove_Registration() {
DiscoveryRegistration registration = SchemaConsumer
.startDiscovery(new ServiceDiscoveryOptions().setName("the-discovery"), testClass);
DiscoveryRegistration sameRegistration = SchemaConsumer
.startDiscovery(new ServiceDiscoveryOptions().setName("the-discovery"), testClass);
assertNotNull(registration);
assertEquals(registration, sameRegistration);
assertEquals(1, testClass.managedDiscoveries().size());
SchemaConsumer.stopDiscovery(registration, testClass);
assertEquals(0, testClass.managedDiscoveries().size());
DiscoveryRegistration registration2 = SchemaConsumer
.startDiscovery(new ServiceDiscoveryOptions().setName("the-discovery"), testClass);
assertNotNull(registration);
assertEquals(1, testClass.managedDiscoveries().size());
SchemaConsumer.stopDiscovery(registration2.getDiscoveryOptions(), testClass);
assertEquals(0, testClass.managedDiscoveries().size());
}
示例7: getOrCreateDiscovery
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的package包/类
/**
* Gets an existing managed repository, or creates it.
*
* @param options the service discovery options
* @param closeHandler the action to perform when {@code discovery.close()} is called
* @return the managed service discovery
*/
protected ServiceDiscovery getOrCreateDiscovery(ServiceDiscoveryOptions options, Action<Void> closeHandler) {
if (options.getName() == null) {
options.setName(getNodeId(vertx));
}
String discoveryName = options.getName();
if (serviceDiscoveries.containsKey(discoveryName)) {
return serviceDiscoveries.get(discoveryName);
}
ServiceDiscovery discovery = ServiceDiscovery.create(vertx, options);
if (closeHandler != null) {
discovery = ManagedServiceDiscovery.of(discovery, closeHandler);
serviceDiscoveries.put(discoveryName, (ManagedServiceDiscovery) discovery);
}
return discovery;
}
示例8: should_Implement_Proper_Reference_Equality
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的package包/类
@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
}
开发者ID:engagingspaces,项目名称:vertx-graphql-service-discovery,代码行数:23,代码来源:AbstractRegistrationTest.java
示例9: register
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的package包/类
/**
* Registers a schema definition created by the
* {@link GraphQLService}.
* <p>
* The provided registration is cloned, completed with publisher-related information, registered and then returned.
*
* @param partialRegistration the partially completed schema registration
* @param options the service discovery options to add
* @param publishedHandler the event handler to invoke on schema published events
* @param unpublishedHandler the event handler to invoke on schema unpublished events
* @return the completed schema registration
*/
protected SchemaRegistration register(
SchemaRegistration partialRegistration, ServiceDiscoveryOptions options,
SchemaPublishedHandler<SchemaRegistration> publishedHandler,
SchemaUnpublishedHandler<SchemaRegistration> unpublishedHandler) {
// First start listening to schema events.
registerSchemaEventConsumers(options, publishedHandler, unpublishedHandler);
// Then register service consumer created from schema definition, if it was not registered yet.
MessageConsumer<JsonObject> serviceConsumer = registerSchemaServiceConsumer(
partialRegistration.getRecord(), partialRegistration.getSchemaDefinition());
// Complete the schema registration
SchemaRegistration fullRegistration = SchemaRegistration.create(partialRegistration.getDiscovery(), options,
partialRegistration.getRecord(), partialRegistration.getSchemaDefinition(), serviceConsumer);
return super.register(options.getName(), fullRegistration);
}
示例10: should_Return_Failure_When_Schema_Definition_Not_Provided
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的package包/类
@Test
public void should_Return_Failure_When_Schema_Definition_Not_Provided(TestContext context) {
Async async = context.async(4);
schemaPublisher.publish(new ServiceDiscoveryOptions(), null, rh -> {
assertFalse(rh.succeeded());
async.countDown();
});
schemaPublisher.publish(new ServiceDiscoveryOptions(), null, null, rh -> {
assertFalse(rh.succeeded());
async.countDown();
});
schemaPublisher.publishAll(new ServiceDiscoveryOptions(), rh -> {
assertFalse(rh.succeeded());
async.countDown();
});
GraphQLSchema[] schemas = null;
schemaPublisher.publishAll(new ServiceDiscoveryOptions(), rh -> {
assertFalse(rh.succeeded());
async.countDown();
}, schemas);
async.awaitSuccess();
}
示例11: setUp
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的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");
}
示例12: setUp
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的package包/类
@Before
public void setUp(TestContext tc) {
Async async = tc.async();
vertx = Vertx.vertx();
Record record = MessageSource.createRecord("portfolio-events", "portfolio", JsonObject
.class);
ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions()
.setBackendConfiguration(new JsonObject().put("backend-name", DefaultServiceDiscoveryBackend.class.getName())))
.publish(record,
r -> {
if (r.failed()) {
r.cause().printStackTrace();
tc.fail(r.cause());
}
vertx.deployVerticle(AuditVerticle.class.getName(), new DeploymentOptions().setConfig(CONFIGURATION), tc.asyncAssertSuccess(s -> async.complete()));
});
}
示例13: init
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的package包/类
protected void init() {
name = DEFAULT_NAME;
healthPathCheck = DEFAULT_HEALTH_PATH_CHECK;
healthCheck = true;
address = DEFAULT_LOCALHOST;
port = DEFAULT_PORT;
httpServerOptions = new HttpServerOptions();
circuitBreakerOptions = new CircuitBreakerOptions();
serviceDiscoveryOptions = new ServiceDiscoveryOptions();
config = new JsonObject();
}
示例14: ServiceDiscoveryFilter
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的package包/类
ServiceDiscoveryFilter(Vertx vertx, JsonObject config) {
this.vertx = vertx;
JsonObject discoveryConfig = config.getJsonObject("service.discovery", new JsonObject());
ServiceDiscoveryOptions options = new ServiceDiscoveryOptions(discoveryConfig);
ServiceFinder serviceFinder = ServiceFinder.create(vertx,
ServiceDiscovery.create(vertx, options));
JsonObject loadBalanceConfig = config.getJsonObject("load.balance", new JsonObject());
LoadBalanceOptions loadBalanceOptions = new LoadBalanceOptions(loadBalanceConfig);
loadBalance = LoadBalance.create(serviceFinder, loadBalanceOptions);
JsonObject circuitConfig = config.getJsonObject("circuit.breaker", new JsonObject());
String stateAnnounce =
circuitConfig.getString("state.announce", "direwolves.circuitbreaker.announce");
vertx.eventBus().<JsonObject>consumer(stateAnnounce, msg -> {
JsonObject jsonObject = msg.body();
String serverId = jsonObject.getString("name");
String state = jsonObject.getString("state");
if ("open".equalsIgnoreCase(state)) {
LoadBalanceStats.instance().get(serverId).setCircuitBreakerTripped(true);
}
if ("close".equalsIgnoreCase(state)) {
LoadBalanceStats.instance().get(serverId).setCircuitBreakerTripped(false);
}
if ("halfOpen".equalsIgnoreCase(state)) {
LoadBalanceStats.instance().get(serverId).setCircuitBreakerTripped(false);
}
});
}
示例15: testSetup
import io.vertx.servicediscovery.ServiceDiscoveryOptions; //导入依赖的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();
});
});
}