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


Java ServiceDiscovery.getRecord方法代码示例

本文整理汇总了Java中io.vertx.servicediscovery.ServiceDiscovery.getRecord方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceDiscovery.getRecord方法的具体用法?Java ServiceDiscovery.getRecord怎么用?Java ServiceDiscovery.getRecord使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.servicediscovery.ServiceDiscovery的用法示例。


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

示例1: example2

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

示例2: example2

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

示例3: executeQuery

import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
/**
 * Executes the parametrized GraphQL query and its variables against the specified schema definition
 * (aka the graphql service name) that is published to the service discovery with the specified name.
 * <p>
 * On success a {@link QueryResult} is returned. Note that at this point the GraphQL query may still have failed,
 * so be sure to check the {@link QueryResult#getErrors()} property afterwards.
 * <p>
 * The top-level keys in the `variables` json represent the variable names that are used in the query string, and
 * are passed with their corresponding values to the query executor.
 *
 * @param discoveryName the name of the service discovery
 * @param schemaName    the name of the schema definition to query
 * @param query         the GraphQL query
 * @param variables     the variables to pass to the query executor
 * @param resultHandler the result handler
 */
default void executeQuery(String discoveryName, String schemaName, String query,
                          JsonObject variables, Handler<AsyncResult<QueryResult>> resultHandler) {
    Objects.requireNonNull(schemaName, "Schema definition name cannot be null");
    Objects.requireNonNull(query, "GraphQL query cannot be null");
    Objects.requireNonNull(resultHandler, "Query result handler cannot be null");

    if (!managedDiscoveries().contains(discoveryName)) {
        resultHandler.handle(Future.failedFuture("Service discovery with name '" + discoveryName +
                "' is not managed by this schema consumer"));
        return;
    }
    ServiceDiscovery discovery = discoveryRegistrar().getDiscovery(discoveryName);
    discovery.getRecord(record -> schemaName.equals(record.getName()), rh -> {
        if (rh.succeeded() && rh.result() != null) {
            GraphQLClient.executeQuery(discovery, rh.result(), query, variables, resultHandler);
        } else {
            resultHandler.handle(Future.failedFuture(
                    "Failed to find published schema '" + schemaName + "' in repository: " + discoveryName));
        }
    });
}
 
开发者ID:engagingspaces,项目名称:vertx-graphql-service-discovery,代码行数:38,代码来源:SchemaConsumer.java

示例4: example2

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

示例5: getSchemaProxy

import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
/**
 * Lookup a GraphQL service record using the provided filter and if found, retrieve the service proxy of type
 * {@link Queryable} used for querying.
 *
 * @param discovery     the service discovery instance
 * @param filter        the filter to select the schema
 * @param resultHandler the result handler
 */
static void getSchemaProxy(ServiceDiscovery discovery, JsonObject filter,
                           Handler<AsyncResult<Queryable>> resultHandler) {
    Objects.requireNonNull(discovery, "Service discovery cannot be null");
    Objects.requireNonNull(resultHandler, "Schema proxy result handler cannot be null");

    discovery.getRecord(filter, rh -> {
        if (rh.failed()) {
            resultHandler.handle(Future.failedFuture(rh.cause()));
        } else {
            if (rh.result() == null) {
                resultHandler.handle(Future.failedFuture("Failed to find schema proxy using filter " + filter));
            } else {
                Record record = rh.result();
                if (!SERVICE_TYPE.equals(record.getType())) {
                    resultHandler.handle(Future.failedFuture("Record '" + record.getName() +
                            "' is of wrong type '" + record.getType() + "'. Expected: " + SERVICE_TYPE));
                } else {
                    getSchemaProxy(discovery, rh.result(), resultHandler);
                }
            }
        }
    });
}
 
开发者ID:engagingspaces,项目名称:vertx-graphql-service-discovery,代码行数:32,代码来源:GraphQLClient.java

示例6: getProxy

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

示例7: getServiceProxy

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

示例8: getOAuth2Provider

import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
static void getOAuth2Provider(ServiceDiscovery discovery, JsonObject filter, Handler<AsyncResult<OAuth2Auth>> resultHandler) {
	discovery.getRecord(filter, ar -> {
		if (ar.failed() || ar.result() == null) {
			resultHandler.handle(Future.failedFuture("No matching record"));
		} else {
			resultHandler.handle(Future.succeededFuture(discovery.getReference(ar.result()).get()));
		}
	});
}
 
开发者ID:pflima92,项目名称:jspare-vertx-ms-blueprint,代码行数:10,代码来源:OAuth2Service.java

示例9: getClient

import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
/**
 * Convenient method that looks for a HTTP endpoint and provides the configured {@link HttpClient}. The async result
 * is marked as failed is there are no matching services, or if the lookup fails.
 *
 * @param discovery     The service discovery instance
 * @param filter        The filter
 * @param resultHandler The result handler
 */
static void getClient(ServiceDiscovery discovery, Function<Record, Boolean> filter, Handler<AsyncResult<HttpClient>>
  resultHandler) {
  discovery.getRecord(filter, ar -> {
    if (ar.failed() || ar.result() == null) {
      resultHandler.handle(Future.failedFuture("No matching record"));
    } else {
      resultHandler.handle(Future.succeededFuture(discovery.<HttpClient>getReference(ar.result()).get()));
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:19,代码来源:HttpEndpoint.java

示例10: getRedisClient

import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
/**
 * Convenient method that looks for a Redis data source and provides the configured {@link io.vertx.redis.RedisClient}.
 * The async result is marked as failed is there are no matching services, or if the lookup fails.
 *
 * @param discovery             The service discovery instance
 * @param filter                The filter, optional
 * @param consumerConfiguration The additional consumer configuration
 * @param resultHandler         The result handler
 */
static void getRedisClient(ServiceDiscovery discovery, JsonObject filter, JsonObject consumerConfiguration,
                           Handler<AsyncResult<RedisClient>> resultHandler) {
  discovery.getRecord(filter, ar -> {
    if (ar.failed() || ar.result() == null) {
      resultHandler.handle(Future.failedFuture("No matching record"));
    } else {
      resultHandler.handle(Future.succeededFuture(
        discovery.<RedisClient>getReferenceWithConfiguration(ar.result(), consumerConfiguration).get()));
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:21,代码来源:RedisDataSource.java

示例11: getJDBCClient

import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
/**
 * Convenient method that looks for a JDBC datasource source and provides the configured {@link io.vertx.ext.jdbc.JDBCClient}. The
 * async result is marked as failed is there are no matching services, or if the lookup fails.
 *
 * @param discovery     The service discovery instance
 * @param filter        The filter, optional
 * @param resultHandler The result handler
 */
static void getJDBCClient(ServiceDiscovery discovery, JsonObject filter,
                          Handler<AsyncResult<JDBCClient>> resultHandler) {
  discovery.getRecord(filter, ar -> {
    if (ar.failed() || ar.result() == null) {
      resultHandler.handle(Future.failedFuture("No matching record"));
    } else {
      resultHandler.handle(Future.succeededFuture(discovery.<JDBCClient>getReference(ar.result()).get()));
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:19,代码来源:JDBCDataSource.java

示例12: getWebClient

import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
/**
 * Convenient method that looks for a HTTP endpoint and provides the configured {@link WebClient}. The async result
 * is marked as failed is there are no matching services, or if the lookup fails. This method accepts a
 * configuration for the HTTP client.
 *
 * @param discovery     The service discovery instance
 * @param filter        The filter
 * @param conf          the configuration of the client
 * @param resultHandler The result handler
 */
static void getWebClient(ServiceDiscovery discovery, Function<Record, Boolean> filter, JsonObject conf,
                      Handler<AsyncResult<WebClient>> resultHandler) {
  discovery.getRecord(filter, ar -> {
    if (ar.failed() || ar.result() == null) {
      resultHandler.handle(Future.failedFuture("No matching record"));
    } else {
      resultHandler.handle(Future.succeededFuture(
        discovery.<HttpClient>getReferenceWithConfiguration(ar.result(), conf).getAs(WebClient.class)));
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:22,代码来源:HttpEndpoint.java

示例13: getConsumer

import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
/**
 * Convenient method that looks for a message source and provides the configured {@link MessageConsumer}. The
 * async result is marked as failed is there are no matching services, or if the lookup fails.
 *
 * @param discovery     The service discovery instance
 * @param filter        The filter, optional
 * @param resultHandler The result handler
 * @param <T>           The class of the message
 */
static <T> void getConsumer(ServiceDiscovery discovery, JsonObject filter,
                            Handler<AsyncResult<MessageConsumer<T>>>
                                resultHandler) {
  discovery.getRecord(filter, ar -> {
    if (ar.failed() || ar.result() == null) {
      resultHandler.handle(Future.failedFuture("No matching record"));
    } else {
      resultHandler.handle(Future.succeededFuture(discovery.<MessageConsumer<T>>getReference(ar.result()).get()));
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:21,代码来源:MessageSource.java

示例14: getMongoClient

import io.vertx.servicediscovery.ServiceDiscovery; //导入方法依赖的package包/类
/**
 * Convenient method that looks for a Mongo datasource source and provides the configured {@link io.vertx.ext.mongo.MongoClient}. The
 * async result is marked as failed is there are no matching services, or if the lookup fails.
 *
 * @param discovery     The service discovery instance
 * @param filter        The filter, optional
 * @param resultHandler The result handler
 */
static void getMongoClient(ServiceDiscovery discovery, JsonObject filter,
                           Handler<AsyncResult<MongoClient>> resultHandler) {
  discovery.getRecord(filter, ar -> {
    if (ar.failed() || ar.result() == null) {
      resultHandler.handle(Future.failedFuture("No matching record"));
    } else {
      resultHandler.handle(Future.succeededFuture(discovery.getReference(ar.result()).get()));
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:19,代码来源:MongoDataSource.java


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