本文整理汇总了Java中io.vertx.servicediscovery.Record类的典型用法代码示例。如果您正苦于以下问题:Java Record类的具体用法?Java Record怎么用?Java Record使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Record类属于io.vertx.servicediscovery包,在下文中一共展示了Record类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dispatchRequests
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
private void dispatchRequests(RoutingContext ctx) {
int offset = "/api/".length();
getAllHttpEndpoints()
.doOnError(err -> badGateway(ctx, err))
.subscribe(list -> {
String path = ctx.request().uri();
if (path.length() < offset) {
notFound(ctx);
return;
}
String prefix = path.substring(offset).split("/")[0];
String apiPath = path.substring(offset + prefix.length());
Optional<Record> client = list.stream()
.filter(r -> r.getMetadata().containsKey("api.name"))
.filter(r -> r.getMetadata().getString("api.name").equals(prefix))
.findAny();
if (!client.isPresent()) {
notFound(ctx);
return;
}
doDispatch(ctx, apiPath, discovery.getReference(client.get()));
});
}
示例2: connect
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
@Override
public RpcClient connect(final JsonObject config,
final JsonObject data,
final Handler<AsyncResult<JsonObject>> handler) {
final Record record = RpcHelper.getRecord(config);
// Service Configuration
final String name = config.getString(Key.NAME);
final String address = config.getString(Key.ADDR);
final JsonObject normalized = RpcHelper.normalize(name, config, record);
this.holder = lookupHolder(this.vertx, name, normalized);
// Get Channel
final IpcType type = Types.fromStr(IpcType.class, config.getString(Key.TYPE));
final RpcStub stub = getStub(type);
// Future result return to client.
final IpcData request = new IpcData();
request.setType(type);
request.setAddress(address);
// The same operation for request.
DataEncap.in(request, record);
DataEncap.in(request, Envelop.success(data));
LOGGER.info(Info.CLIENT_TRAFFIC, request.toString());
final Future<JsonObject> future = stub.traffic(request);
future.setHandler(res -> handler.handle(Future.succeededFuture(res.result())));
return this;
}
示例3: handle
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
public Handler<RoutingContext> handle() {
return context -> {
// Run with circuit breaker
this.breaker.execute(future -> getEndPoints().setHandler(res -> {
if (res.succeeded()) {
final List<Record> records = res.result();
// Find the record hitted. ( Include Path variable such as /xx/yy/:zz/:xy )
final Record hitted = this.arithmetic.search(records, context);
// Complete actions.
if (null == hitted) {
// Service Not Found ( 404 )
reply404Error(context);
} else {
// Find record, dispatch request
final ServiceReference reference = this.discovery.getReference(hitted);
doRequest(context, reference);
}
future.complete();
} else {
// Future failed
future.fail(res.cause());
}
}));
};
}
示例4: deleteService
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
private void deleteService(final ServiceDiscovery discovery,
final Set<String> ids) {
// Delete service from current zero system.
Observable.fromIterable(ids)
.subscribe(id -> {
final String item = ID_MAP.get(id);
discovery.unpublish(item, result -> {
if (result.succeeded()) {
// Delete successfully
final Record record = REGISTRITIONS.get(id);
successLog(record);
// Sync deleted
REGISTRITIONS.remove(id);
ID_MAP.remove(id);
} else {
LOGGER.info(Info.REG_FAILURE, result.cause().getMessage(), "Delete");
}
});
});
}
示例5: addService
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
private void addService(final ServiceDiscovery discovery,
final Set<String> ids,
final ConcurrentMap<String, Record> services) {
// Add service into current zero system.
Observable.fromIterable(ids)
.map(services::get)
.subscribe(item -> discovery.publish(item, result -> {
if (result.succeeded()) {
final Record record = result.result();
// Add successfully
successFinished(record);
} else {
LOGGER.info(Info.REG_FAILURE, result.cause().getMessage(), "Add");
}
}));
}
示例6: calculateServices
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
private ConcurrentMap<Flag, Set<String>> calculateServices(
final ConcurrentMap<String, Record> services) {
// Read new services.
final Set<String> populated = new HashSet<>();
Observable.fromIterable(services.keySet())
.subscribe(populated::add);
// Existed = Yes, Populated = No
final Set<String> deleted = new HashSet<>(REGISTRITIONS.keySet());
deleted.removeAll(populated);
// Existed = Yes, Populated = Yes
final Set<String> updated = new HashSet<>(REGISTRITIONS.keySet());
updated.retainAll(populated);
// Existed = No, Populated = Yes
final Set<String> added = new HashSet<>(populated);
added.removeAll(REGISTRITIONS.keySet());
// Mapping data
final ConcurrentMap<Flag, Set<String>> result = new ConcurrentHashMap<>();
result.put(Flag.DELETE, deleted);
result.put(Flag.NEW, added);
result.put(Flag.UPDATE, updated);
return result;
}
示例7: send
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
public Future<Envelop> send(final Envelop envelop) {
// 1. Extract address
final String address = getValue("to");
final IpcType type = getValue("type");
// 2. Record extract
final Record record = findTarget();
// 3. Convert IpcData
final IpcData data = new IpcData();
data.setType(type);
data.setAddress(address);
// 4. In data
DataEncap.in(data, record);
DataEncap.in(data, envelop);
// 5. Stub
final Spear stub = STUBS.getOrDefault(type, Instance.singleton(UnitySpear.class));
return stub.send(this.vertx, data);
}
示例8: findTarget
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
/**
* Here's the logical of current IPC
* 1. The address contains all the etcd address that published
*
* @return Found record for IPC
*/
private Record findTarget() {
final ConcurrentMap<String, Record> address = ORIGIN.getRegistryData();
final String target = getValue("to");
final String name = getValue("name");
// 1. Find service names
final Record record = address.values().stream()
.filter(item -> name.equals(item.getName()))
.findFirst().orElse(null);
// Service Name
Fn.flingWeb(null == record, this.logger,
_501RpcImplementException.class, getClass(),
name, target, this.event.getAction());
// Address Wrong
Fn.flingWeb(null == record.getMetadata() ||
!target.equals(record.getMetadata().getString("path")), this.logger,
_501RpcAddressWrongException.class, getClass(),
target, name);
this.logger.info(Info.RECORD_FOUND, record.toJson());
return record;
}
示例9: handleRecordList
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
protected Future<Record> handleRecordList(String alias, AsyncResult<List<Record>> resultHandler){
Future<Record> future = Future.future();
if(resultHandler.succeeded()){
// Simple LoadBalance with findAny on stream
Optional<Record> client = resultHandler.result().stream()
.filter(record -> RecordMetadata.of(record.getMetadata()).getName().equals(alias)).findAny();
if(client.isPresent()) future.complete(client.get());
else future.fail(new BusinessException(RECORD_NOT_FOUND_REASON));
}else{
future.fail(resultHandler.cause());
}
return future;
}
示例10: doDispatch
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
private <T> void doDispatch(Future<T> future, Buffer buffer, AsyncResult<Record> resultHandler) {
AuditFuture audit = AuditFuture.create(context).saveRequest(buffer.copy());
if (resultHandler.succeeded()) {
Record record = resultHandler.result();
proxyService.proxy(context, record, buffer).setHandler(ar -> {
audit.saveResponse(record, ar.result());
future.complete();
});
} else {
audit.saveResponse(resultHandler.cause());
future.fail(resultHandler.cause());
}
}
示例11: saveResponse
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
@SneakyThrows
public void saveResponse(Record record, Buffer responseBuffer) {
createFuture.setHandler(res -> {
try {
Audit audit = res.result();
audit
.setRecord(record.toJson())
.setResponseCode(context.response().getStatusCode())
.setResponseContent(new SerialBlob(Optional.ofNullable(responseBuffer)
.orElse(Buffer.buffer()).getBytes()
));
persist(audit, this::notifyAuditResult);
} catch (Exception e) {
log.error("Fail to save response");
}
});
}
示例12: start
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
@Override
public void start() {
ServiceDiscovery.create(vertx, discovery -> {
this.discovery = discovery;
// Create the service object
PortfolioServiceImpl service = new PortfolioServiceImpl(vertx, discovery, config().getDouble("money", 10000.00));
// Register the service proxy on the event bus
ProxyHelper.registerService(PortfolioService.class, vertx.getDelegate(), service, ADDRESS);
Record record = EventBusService.createRecord("portfolio", ADDRESS, PortfolioService.class.getName());
discovery.publish(record, ar -> {
if (ar.succeeded()) {
this.record = record;
System.out.println("Portfolio service published");
// Used for health check
vertx.createHttpServer().requestHandler(req -> req.response().end("OK")).listen(8080);
} else {
ar.cause().printStackTrace();
}
});
});
}
示例13: getMicroServiceRecord
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
/**
* Define microservice options
* servicePort: this is the visible port from outside
* for example you run your service with 8080 on a platform (Clever Cloud, Docker, ...)
* and the visible port is 80
*/
static Record getMicroServiceRecord() {
String serviceName = Optional.ofNullable(System.getenv("SERVICE_NAME")).orElse("John Doe");
String serviceHost = Optional.ofNullable(System.getenv("SERVICE_HOST")).orElse("localhost"); // domain name
Integer servicePort = Integer.parseInt(Optional.ofNullable(System.getenv("SERVICE_PORT")).orElse("80")); // set to 80 on Clever Cloud
String serviceRoot = Optional.ofNullable(System.getenv("SERVICE_ROOT")).orElse("/api");
return HttpEndpoint.createRecord(
serviceName,
serviceHost,
servicePort,
serviceRoot
);
}
示例14: publish
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
private Single<Void> publish(Record record) {
if (isNull(discovery)) {
return Single.error(new Throwable(format("ServiceDiscovery is null, did you forget to call super()?, record: %s",
record.getLocation().encode())));
}
return discovery.rxPublish(record)
.doOnSuccess(this::storeAndLogPublished)
.map(rec -> null);
}
示例15: onPublish
import io.vertx.servicediscovery.Record; //导入依赖的package包/类
protected void onPublish(AsyncResult<Record> resultHandler) {
if (resultHandler.succeeded()) {
record = resultHandler.result();
log.info("{} microservice registered on ServiceDiscovery", resultHandler.result().getName());
} else {
log.error("Fail to registry microservice, fall out of process", resultHandler.cause());
System.exit(CommonExitCode.REGISTRY_SERVICE_DISCOVERY_ERROR);
}
}