Sidecar原理分析
一 先启动几个微服务1 启动eureka2 启动user微服务3 启动sidecar4 启动node-service.js二 访问Eureka Server的路径:http://localhost:8761/eureka/apps/microservice-sidecar-node-service,可获得如下结果<application><name&
·
一 先启动几个微服务
1 启动eureka
2 启动user微服务
3 启动sidecar
4 启动node-service.js
二 访问Eureka Server的路径:http://localhost:8761/eureka/apps/microservice-sidecar-node-service,可获得如下结果
<application>
<name>MICROSERVICE-SIDECAR-NODE-SERVICE</name>
<instance>
<instanceId>
DESKTOP-5SDKDG4:microservice-sidecar-node-service:8070
</instanceId>
<hostName>192.168.0.106</hostName>
<app>MICROSERVICE-SIDECAR-NODE-SERVICE</app>
<ipAddr>192.168.0.106</ipAddr>
<status>UP</status>
<overriddenstatus>UNKNOWN</overriddenstatus>
<port enabled="true">8060</port>
<securePort enabled="false">443</securePort>
<countryId>1</countryId>
<dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
<name>MyOwn</name>
</dataCenterInfo>
<leaseInfo>
<renewalIntervalInSecs>30</renewalIntervalInSecs>
<durationInSecs>90</durationInSecs>
<registrationTimestamp>1530268067983</registrationTimestamp>
<lastRenewalTimestamp>1530268067983</lastRenewalTimestamp>
<evictionTimestamp>0</evictionTimestamp>
<serviceUpTimestamp>1530268067478</serviceUpTimestamp>
</leaseInfo>
<metadata class="java.util.Collections$EmptyMap"/>
<homePageUrl>http://DESKTOP-5SDKDG4:8060/</homePageUrl>
<statusPageUrl>http://DESKTOP-5SDKDG4:8070/info</statusPageUrl>
<healthCheckUrl>http://DESKTOP-5SDKDG4:8070/health</healthCheckUrl>
<vipAddress>microservice-sidecar-node-service</vipAddress>
<secureVipAddress>microservice-sidecar-node-service</secureVipAddress>
<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
<lastUpdatedTimestamp>1530268067983</lastUpdatedTimestamp>
<lastDirtyTimestamp>1530268067473</lastDirtyTimestamp>
<actionType>ADDED</actionType>
</instance>
</application>
从结果可知,注册到Eureka Server上的端口是8060,homePageurl是
http://DESKTOP-5SDKDG4:8060/,恰恰是node-service的端口和首页。因此,注册到Eureka Server上的微服务可使用microservice-sidecar-node-service这个名称请求node-service的接口。
三 由于@EnableSidecar整合了注解@EnableZuulProxy,可尝试访问Sidecar的/routes端点:http://localhost:8070/routes,得到结果如下
{"/microservice-provider-user/**":"microservice-provider-user"}
因此,非JVM微服务可通过Sidecar请求其他注册在Eureka Server的微服务。
四 其他
可尝试将node-service多次启停,并观察Sidecar的/health端点。Sidecar会获取node-service的健康状态,并将状态传播到Eureka Server。使用这种方式,Eureka Server就能感知到非JVM微服务的健康状态。
更多推荐
已为社区贡献24条内容
所有评论(0)