Search in sources :

Example 1 with ResolveServiceRequest

use of com.google.cloud.servicedirectory.v1.ResolveServiceRequest in project java-servicedirectory by googleapis.

the class ServicesResolve method resolveService.

// Resolve a service.
public static void resolveService(String projectId, String locationId, String namespaceId, String serviceId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (LookupServiceClient client = LookupServiceClient.create()) {
        // The service to resolve.
        ServiceName name = ServiceName.of(projectId, locationId, namespaceId, serviceId);
        // Construct the resolve request to be sent to the client.
        ResolveServiceRequest request = ResolveServiceRequest.newBuilder().setName(name.toString()).build();
        // Send the request to resolve the service.
        ResolveServiceResponse resolveResponse = client.resolveService(request);
        // Process the response.
        System.out.println("Resolved Service: " + resolveResponse.getService().getName());
        System.out.println("Endpoints found:");
        for (Endpoint endpoint : resolveResponse.getService().getEndpointsList()) {
            System.out.println(endpoint.getName() + " -- " + endpoint.getAddress() + ":" + endpoint.getPort());
        }
    }
}
Also used : ResolveServiceResponse(com.google.cloud.servicedirectory.v1.ResolveServiceResponse) Endpoint(com.google.cloud.servicedirectory.v1.Endpoint) ServiceName(com.google.cloud.servicedirectory.v1.ServiceName) ResolveServiceRequest(com.google.cloud.servicedirectory.v1.ResolveServiceRequest) LookupServiceClient(com.google.cloud.servicedirectory.v1.LookupServiceClient)

Aggregations

Endpoint (com.google.cloud.servicedirectory.v1.Endpoint)1 LookupServiceClient (com.google.cloud.servicedirectory.v1.LookupServiceClient)1 ResolveServiceRequest (com.google.cloud.servicedirectory.v1.ResolveServiceRequest)1 ResolveServiceResponse (com.google.cloud.servicedirectory.v1.ResolveServiceResponse)1 ServiceName (com.google.cloud.servicedirectory.v1.ServiceName)1