0珊楼、理解
通過sidecar將異構(gòu)平臺的微服務(wù)注冊到Eureka聋伦;讓其和SpringCloud的生態(tài)空間連在一起涮俄;
1、使用
pom.xml`
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-sidecar</artifactId>
</dependency>
application.yml
spring:
application:
name: microservice-sidecar
server:
port: 8070
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
instance:
prefer-ip-address: true
sidecar:
port: 8060
health-uri: http://localhost:8060/health.json
啟動類SidecarApplication.java
@SpringBootApplication
//注冊Sidecar尸闸;@EnableSidecar是一個組合注解
@EnableSidecar
public class SidecarApplication {
public static void main(String[] args) {
System.out.println("Hello Zuul!");
SpringApplication.run(SidecarApplication.class, args);
}
}
注意
- 1彻亲、
當(dāng)異構(gòu)微服務(wù)和eureka不運(yùn)行在同一個hostname上時,我們需要配置
${eureka.instance.hostName}
- 2吮廉、每一個異構(gòu)微服務(wù)節(jié)點就需要一個sidecar苞尝,當(dāng)需要異構(gòu)的微服務(wù)很多時,就很麻煩了宦芦;且sidecar本身對業(yè)務(wù)沒什么作用宙址,僅僅做一個‘匯總’。