当前位置: 首页>>代码示例>>Java>>正文


Java Record类代码示例

本文整理汇总了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()));
      });
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:24,代码来源:GatewayVerticle.java

示例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;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:27,代码来源:RpcClientImpl.java

示例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());
            }
        }));
    };
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:26,代码来源:ServiceJet.java

示例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");
                    }
                });
            });
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:21,代码来源:ZeroApiWorker.java

示例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");
                }
            }));
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:17,代码来源:ZeroApiWorker.java

示例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;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:27,代码来源:ZeroApiWorker.java

示例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);
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:18,代码来源:TunnelClient.java

示例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;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:27,代码来源:TunnelClient.java

示例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;
}
 
开发者ID:pflima92,项目名称:jspare-vertx-ms-blueprint,代码行数:17,代码来源:LoadBalanceServiceImpl.java

示例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());
	}
}
 
开发者ID:pflima92,项目名称:jspare-vertx-ms-blueprint,代码行数:18,代码来源:GatewayProxyRoute.java

示例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");
		}
	});
}
 
开发者ID:pflima92,项目名称:jspare-vertx-ms-blueprint,代码行数:23,代码来源:AuditFuture.java

示例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();
      }
    });

  });
}
 
开发者ID:cescoffier,项目名称:vertx-kubernetes-workshop,代码行数:27,代码来源:PortfolioVerticle.java

示例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
  );
}
 
开发者ID:the-big-bang-theory,项目名称:penny,代码行数:21,代码来源:Parameters.java

示例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);
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:10,代码来源:BaseRxVerticle.java

示例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);
		}
	}
 
开发者ID:pflima92,项目名称:jspare-vertx-ms-blueprint,代码行数:13,代码来源:RestAPIVerticle.java


注:本文中的io.vertx.servicediscovery.Record类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。