Giriş
Şu satırı dahil ederiz
Şu satırı dahil ederiz
import org.springframework.cloud.client.discovery.DiscoveryClient;
getInstances metodu - service name
ÖrnekŞöyle yaparız
public static final String URL_DISCOVER_BOOKS = "%s/books?bridgeEndpoint=true";@Autowiredprivate DiscoveryClient discoveryClient;String.format(URL_DISCOVER_BOOKS,
discoveryClient.getInstances("discovery-client").get(0).getUri());
Örnek
Şöyle yaparız
// (Need!!) eureka.client.fetchRegistry=trueList<ServiceInstance> instances = this.discoveryClient.getInstances(serviceId);if (instances == null || instances.isEmpty()) {return "No instances for service: " + serviceId;}String html = "<h2>Instances for Service Id: " + serviceId + "</h2>";for (ServiceInstance serviceInstance : instances) {html += "<h3>Instance: " + serviceInstance.getUri() + "</h3>";html += "Host: " + serviceInstance.getHost() + "<br>";html += "Port: " + serviceInstance.getPort() + "<br>";}return html;
Tüm servis isimlerini döner.
Şöyle yaparız
List<String> serviceIds = this.discoveryClient.getServices();
Hiç yorum yok:
Yorum Gönder