Java Code Examples for org.springframework.cloud.client.ServiceInstance#getServiceId()
The following examples show how to use
org.springframework.cloud.client.ServiceInstance#getServiceId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultServiceLoadBalancer.java From camel-spring-boot with Apache License 2.0 | 5 votes |
protected ServiceDefinition convertServiceInstanceToServiceDefinition(ServiceInstance instance) { return new DefaultServiceDefinition( instance.getServiceId(), instance.getHost(), instance.getPort(), instance.getMetadata() ); }
Example 2
Source File: NamingService.java From WeEvent with Apache License 2.0 | 5 votes |
public static NamingService convert(ServiceInstance instance) { NamingService namingService = new NamingService(); namingService.serviceId = instance.getServiceId(); namingService.instanceId = instance.getInstanceId(); namingService.host = instance.getHost(); namingService.port = instance.getPort(); namingService.uri = instance.getUri().toString(); namingService.secure = instance.isSecure(); return namingService; }
Example 3
Source File: ClientDiscoveryImpl.java From BootNettyRpc with Apache License 2.0 | 5 votes |
private List<NettyClient> convertNettyClients(List<ServiceInstance> serviceInstances) { if (CollectionUtils.isEmpty( serviceInstances )) { return null; } List<NettyClient> nettyClients = new CopyOnWriteArrayList<>(); for (ServiceInstance serviceInstance : serviceInstances) { NettyClient nettyClient = new NettyClient(); Map<String, String> metadata = serviceInstance.getMetadata(); String host = metadata.get( NettyRpcConstants.NETTY_SERVER_HOST ); if (StringUtils.isEmpty( host )) { host = serviceInstance.getHost(); } nettyClient.setHost( host ); String name = metadata.get( NettyRpcConstants.NETTY_SERVER_NAME ); if (StringUtils.isEmpty( name )) { name = serviceInstance.getServiceId(); } nettyClient.setName( name ); String port = metadata.get( NettyRpcConstants.NETTY_SERVER_PORT ); if (StringUtils.isEmpty( port )) { throw new CommonException( "netty server " + name + " 's port connot be null" ); } nettyClient.setPort( Integer.valueOf( port ) ); nettyClients.add( nettyClient ); } return nettyClients; }
Example 4
Source File: DiscoveryClientRouteDefinitionLocator.java From spring-cloud-gateway with Apache License 2.0 | 5 votes |
protected RouteDefinition buildRouteDefinition(Expression urlExpr, ServiceInstance serviceInstance) { String serviceId = serviceInstance.getServiceId(); RouteDefinition routeDefinition = new RouteDefinition(); routeDefinition.setId(this.routeIdPrefix + serviceId); String uri = urlExpr.getValue(this.evalCtxt, serviceInstance, String.class); routeDefinition.setUri(URI.create(uri)); // add instance metadata routeDefinition.setMetadata(new LinkedHashMap<>(serviceInstance.getMetadata())); return routeDefinition; }
Example 5
Source File: SampleLatticeApplication.java From spring-cloud-lattice with Apache License 2.0 | 5 votes |
@RequestMapping("/hi") public String hi() { ServiceInstance instance = discoveryClient.getLocalServiceInstance(); String msg = instance.getServiceId() + ":" + instance.getHost() + ":" + instance.getPort(); log.info("/hi called: " + msg); return msg; }
Example 6
Source File: ServiceBController.java From spring-cloud-consul-example with MIT License | 4 votes |
@RequestMapping(value = "/", method = RequestMethod.GET) public String printServiceB() { ServiceInstance serviceInstance = discoveryClient.getLocalServiceInstance(); return serviceInstance.getServiceId() + " (" + serviceInstance.getHost() + ":" + serviceInstance.getPort() + ")" + "===>Say " + msg; }
Example 7
Source File: AServiceController.java From spring-cloud-consul-example with MIT License | 4 votes |
@RequestMapping(value = "/", method = RequestMethod.GET) public String printServiceA() { ServiceInstance serviceInstance = discoveryClient.getLocalServiceInstance(); return serviceInstance.getServiceId() + " (" + serviceInstance.getHost() + ":" + serviceInstance.getPort() + ")" + "===>name:" + name + "<br/>" + serviceBClient.printServiceB(); }
Example 8
Source File: DiscoveredResource.java From spring-cloud-commons with Apache License 2.0 | 3 votes |
private Link discoverLink() { try { ServiceInstance service = this.provider.getServiceInstance(); if (service == null) { return null; } URI uri = service.getUri(); String serviceId = service.getServiceId(); this.log.debug("Discovered {} system at {}. Discovering resource…", serviceId, uri); Traverson traverson = new Traverson(uri, MediaTypes.HAL_JSON); Link link = this.traversal.buildTraversal(traverson).asTemplatedLink(); this.log.debug("Found link pointing to {}.", link.getHref()); return link; } catch (RuntimeException o_O) { this.link = null; this.log.debug("Target system unavailable. Got: ", o_O.getMessage()); return null; } }