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


Java ServiceReference类代码示例

本文整理汇总了Java中io.vertx.servicediscovery.ServiceReference的典型用法代码示例。如果您正苦于以下问题:Java ServiceReference类的具体用法?Java ServiceReference怎么用?Java ServiceReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ServiceReference类属于io.vertx.servicediscovery包,在下文中一共展示了ServiceReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handle

import io.vertx.servicediscovery.ServiceReference; //导入依赖的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

示例2: retrieveAuditService

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
private Future<Void> retrieveAuditService() {
    Future<Void> future = Future.future();

    discovery.getRecord(new JsonObject().put("name", "audit"), ar -> {
        if (ar.failed()) {
            future.fail(ar.cause());
        } else if (ar.result() == null) {
            future.fail("Could not retrieve audit service");
        } else {
            ServiceReference reference = discovery.getReference(ar.result());
            this.root = reference.record().getLocation().getString("root");
            this.client = reference.get();
            future.complete();
        }
    });

    return future;
}
 
开发者ID:docker-production-aws,项目名称:microtrader,代码行数:19,代码来源:DashboardVerticle.java

示例3: example2

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
public void example2(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(new JsonObject().put("name", "some-http-service"), ar -> {
    if (ar.succeeded() && ar.result() != null) {
      // Retrieve the service reference
      ServiceReference reference = discovery.getReference(ar.result());
      // Retrieve the service object
      HttpClient client = reference.getAs(HttpClient.class);

      // You need to path the complete path
      client.getNow("/api/persons", response -> {

        // ...

        // Dont' forget to release the service
        reference.release();

      });
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:22,代码来源:HTTPEndpointExamples.java

示例4: example2_webclient

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
public void example2_webclient(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(new JsonObject().put("name", "some-http-service"), ar -> {
    if (ar.succeeded() && ar.result() != null) {
      // Retrieve the service reference
      ServiceReference reference = discovery.getReference(ar.result());
      // Retrieve the service object
      WebClient client = reference.getAs(WebClient.class);

      // You need to path the complete path
      client.get("/api/persons").send(
        response -> {

          // ...

          // Dont' forget to release the service
          reference.release();

        });
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:23,代码来源:HTTPEndpointExamples.java

示例5: example2

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
public void example2(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(new JsonObject().put("name", "some-message-source-service"), ar -> {
    if (ar.succeeded() && ar.result() != null) {
      // Retrieve the service reference
      ServiceReference reference = discovery.getReference(ar.result());
      // Retrieve the service object
      MessageConsumer<JsonObject> consumer = reference.getAs(MessageConsumer.class);

      // Attach a message handler on it
      consumer.handler(message -> {
        // message handler
        JsonObject payload = message.body();
      });
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:18,代码来源:MessageSourceExamples.java

示例6: example2

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
public void example2(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(
    new JsonObject().put("name", "some-redis-data-source-service"), ar -> {
      if (ar.succeeded() && ar.result() != null) {
        // Retrieve the service reference
        ServiceReference reference = discovery.getReference(ar.result());

        // Retrieve the service instance
        RedisClient client = reference.getAs(RedisClient.class);

        // ...

        // when done
        reference.release();
      }
    });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:19,代码来源:RedisDataSourceExamples.java

示例7: example2

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
public void example2(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(
      new JsonObject().put("name", "some-data-source-service"),
      ar -> {
        if (ar.succeeded() && ar.result() != null) {
          // Retrieve the service reference
          ServiceReference reference = discovery.getReferenceWithConfiguration(
              ar.result(), // The record
              new JsonObject().put("username", "clement").put("password", "*****")); // Some additional metadata

          // Retrieve the service object
          JDBCClient client = reference.getAs(JDBCClient.class);

          // ...

          // when done
          reference.release();
        }
      });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:22,代码来源:JDBCDataSourceExamples.java

示例8: example2

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
public void example2(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(
    new JsonObject().put("name", "some-data-source-service"),
    ar -> {
      if (ar.succeeded() && ar.result() != null) {
        // Retrieve the service reference
        ServiceReference reference = discovery.getReferenceWithConfiguration(
          ar.result(), // The record
          new JsonObject().put("username", "clement").put("password", "*****")); // Some additional metadata

        // Retrieve the service object
        MongoClient client = reference.get();

        // ...

        // when done
        reference.release();
      }
    });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:22,代码来源:MongoDataSourceExamples.java

示例9: getProxy

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
/**
 * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service).
 * This is a convenient method to avoid explicit lookup and then retrieval of the service. A filter based on the
 * request interface is used.
 *
 * @param discovery     the service discovery instance
 * @param itf           the service interface
 * @param resultHandler the result handler
 * @param <T>           the service interface
 * @return {@code null}
 */
@GenIgnore // Java only
static <T> T getProxy(ServiceDiscovery discovery, Class<T> itf, Handler<AsyncResult<T>>
  resultHandler) {
  JsonObject filter = new JsonObject().put("service.interface", itf.getName());
  discovery.getRecord(filter, ar -> {
    if (ar.failed()) {
      resultHandler.handle(Future.failedFuture(ar.cause()));
    } else {
      if (ar.result() == null) {
        resultHandler.handle(Future.failedFuture("Cannot find service matching with " + filter));
      } else {
        ServiceReference service = discovery.getReference(ar.result());
        resultHandler.handle(Future.succeededFuture(service.get()));
      }
    }
  });
  return null;
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:30,代码来源:EventBusService.java

示例10: getServiceProxy

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
/**
 * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service).
 * This is a convenient method to avoid explicit lookup and then retrieval of the service. This method requires to
 * have the {@code clientClass} set with the expected set of client. This is important for usages not using Java so
 * you can pass the expected type.
 *
 * @param discovery     the service discovery
 * @param filter        the filter
 * @param clientClass   the client class
 * @param resultHandler the result handler
 * @param <T>           the type of the client class
 * @return {@code null} - do not use
 */
static <T> T getServiceProxy(ServiceDiscovery discovery,
                             Function<Record, Boolean> filter,
                             Class<T> clientClass,
                             Handler<AsyncResult<T>> resultHandler) {
  discovery.getRecord(filter, ar -> {
    if (ar.failed()) {
      resultHandler.handle(Future.failedFuture(ar.cause()));
    } else {
      if (ar.result() == null) {
        resultHandler.handle(Future.failedFuture("Cannot find service matching with " + filter));
      } else {
        ServiceReference service = discovery.getReference(ar.result());
        resultHandler.handle(Future.succeededFuture(service.getAs(clientClass)));
      }
    }
  });
  return null;
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:32,代码来源:EventBusService.java

示例11: getServiceProxyWithJsonFilter

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
/**
 * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service).
 * This is a convenient method to avoid explicit lookup and then retrieval of the service. This method requires to
 * have the {@code clientClass} set with the expected set of client. This is important for usages not using Java so
 * you can pass the expected type.
 *
 * @param discovery     the service discovery
 * @param filter        the filter as json object
 * @param clientClass   the client class
 * @param resultHandler the result handler
 * @param <T>           the type of the client class
 * @return {@code null} - do not use
 */
static <T> T getServiceProxyWithJsonFilter(ServiceDiscovery discovery,
                                           JsonObject filter,
                                           Class<T> clientClass,
                                           Handler<AsyncResult<T>> resultHandler) {
  discovery.getRecord(filter, ar -> {
    if (ar.failed()) {
      resultHandler.handle(Future.failedFuture(ar.cause()));
    } else {
      if (ar.result() == null) {
        resultHandler.handle(Future.failedFuture("Cannot find service matching with " + filter));
      } else {
        ServiceReference service = discovery.getReference(ar.result());
        resultHandler.handle(Future.succeededFuture(service.getAs(clientClass)));
      }
    }
  });
  return null;
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:32,代码来源:EventBusService.java

示例12: getSchemaProxy

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
/**
 * Get the GraphQL service proxy that is associated with the provided service record.
 *
 * @param discovery     the service discovery instance
 * @param record        the service record of a published GraphQL service
 * @param resultHandler the result handler
 */
static void getSchemaProxy(ServiceDiscovery discovery, Record record,
                           Handler<AsyncResult<Queryable>> resultHandler) {
    Objects.requireNonNull(discovery, "Service discovery cannot be null");
    Objects.requireNonNull(record, "Record cannot be null");
    Objects.requireNonNull(resultHandler, "Schema proxy result handler cannot be null");

    if (!SERVICE_TYPE.equals(record.getType())) {
        resultHandler.handle(Future.failedFuture("Record '" + record.getName() +
                "' is of wrong type '" + record.getType() + "'. Expected: " + SERVICE_TYPE));
    } else if (!Status.UP.equals(record.getStatus())) {
        resultHandler.handle(Future.failedFuture("Record status indicates service '" + record.getName() +
                "' is: " + record.getStatus() + ". Expected: " + Status.UP));
    } else if (record.getRegistration() == null) {
        resultHandler.handle(Future.failedFuture("Record '" + record.getName() +
                "' has no service discovery registration"));
    } else {
        ServiceReference reference = discovery.getReference(record);
        Queryable queryable = reference.cached() == null ? reference.get() : reference.cached();
        reference.release();
        resultHandler.handle(Future.succeededFuture(queryable));
    }
}
 
开发者ID:engagingspaces,项目名称:vertx-graphql-service-discovery,代码行数:30,代码来源:GraphQLClient.java

示例13: publishTestRecord

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
@Test
public void givenServiceDiscovery_whenPublishServiceWithMetadataAndLookupForItsServiceReferencePassingConfiguration_thenShouldGetTheReferenceUponTheseConfigurations(TestContext context) throws Exception {
    publishTestRecord(record, context.asyncAssertSuccess(record -> {
        ServiceReference reference = vertxServiceDiscovery.lookupForAReferenceWithConfiguration(record, metadata);
        assertEquals(VALUE, reference.record().getMetadata().getString(KEY));
    }));
}
 
开发者ID:GwtDomino,项目名称:domino,代码行数:8,代码来源:VertxServiceDiscoveryTest.java

示例14: get

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
@Override
public ServiceReference get(Vertx vertx, ServiceDiscovery discovery, Record record, JsonObject configuration) {
	Objects.requireNonNull(vertx);
	Objects.requireNonNull(record);
	Objects.requireNonNull(discovery);
	return new OAuth2ServiceReference(vertx, discovery, record, configuration);
}
 
开发者ID:pflima92,项目名称:jspare-vertx-ms-blueprint,代码行数:8,代码来源:OAuth2ServiceImpl.java

示例15: getServiceRef

import io.vertx.servicediscovery.ServiceReference; //导入依赖的package包/类
private void getServiceRef(JsonObject filter, Handler<AsyncResult<ServiceReference>> handler) {
  discovery.getRecord(filter, ar -> {
    if (ar.succeeded() && ar.result() != null) {
      ServiceReference ref = discovery.<HttpClient>getReference(ar.result());
      handler.handle(Future.succeededFuture(ref));
    } else {
      handler.handle(Future.failedFuture(ar.cause()));
    }
  });
}
 
开发者ID:vietj,项目名称:vertx-service-flow,代码行数:11,代码来源:FlowImpl.java


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