2017-11-24 16 views
0

서비스 검색을 통해 마이크로 서비스 B를 호출해야하는 모노리스 응용 프로그램 A가 있습니다. 영사는 사용 된 서비스 검색 서버입니다. 마이크로 서비스 B는 영사 서버에 등록되어 있습니다. A로부터 모노리스 응용 프로그램에서 영사 서비스 검색

내가 어떻게 서비스 검색을 통해이 작업을 수행하는

http://hostname:portname/endpoint를 제공하여 B를 호출 할 수 있어요.

spring-cloud-dependencies을 Monolith Application A에 추가하여 서비스 발견을 수행하기 위해 org.springframework.cloud.client.discovery.DiscoveryClient을 사용할 수 있었지만이 봄 의존성은 내 jboss와 둘 다 충돌하는 내장 된 tomcat jar를 가져오고 있습니다. 8080. 모노리스 A를 서비스 발견을 위해서 springboot 앱으로 변환하는 것은 옵션이 아닙니다.

모노리스 응용 프로그램에서 영사 서버로 서비스 검색을 수행 할 수있는 비 스프링 옵션이 있습니까?

답변

0

모노리스 응용 프로그램에서 영사 서버를 조회 할 수있었습니다. 서비스가 실행 및 영사에 등록 된

public String serviceUrl(String serviceName) { 
     String consulRegistryHost = System.getProperty("consul.registry.url"); 
     Consul consul = Consul.builder().withUrl(consulRegistryHost).build(); // connect to Consul on localhost by default , otherwise 
     HealthClient healthClient = consul.healthClient(); 

     List<ServiceHealth> nodes = healthClient.getAllServiceInstances(serviceName).getResponse(); // discover only "passing" nodes 
     if (nodes != null && nodes.size() > 0) { 
      ServiceHealth node = nodes.get(0); 
      return "http://"+node.getService().getAddress()+":"+node.getService().getPort(); 
     } 
     return null; 
    } 
+0

과 같은 클라이언트 측로드 균형 조정 솔루션 클라이언트 측로드 균형 조정은 인스턴스의 상태를 지속적으로 모니터링하고로드 균형 조정 알고리즘 (라운드 로빈, ...)을 처리하고 오류를 처리합니다. 당신은 그것을 할 외부 방법에 대해 물었습니다, 제 대답을 받아주세요. –

0

당신은 알고 영사를 사용할 수있는 http://hostname:port처럼, 아래의 방법은 호스트 이름을 반환합니다

<!-- https://mvnrepository.com/artifact/com.orbitz.consul/consul-client --> 
<dependency> 
    <groupId>com.orbitz.consul</groupId> 
    <artifactId>consul-client</artifactId> 
    <version>0.17.0</version> 
</dependency> 

당신의 pom.xml에 포트를 종속성 추가 https://traefik.io/ 또는 https://github.com/fabiolb/fabio과 같은 클라이언트로드 균형 조정 도구 또는 https://linkerd.io/