1.启动miroservice-discovery-eureka.
2.编写一个符合上面XSD的XML,命名为rest-api-test.xml 内容如下:
<instance>
<instanceId>SKY-20181224VZL</instanceId> #一般为计算机名
<hostName>192.168.128.1</hostName> #ip
<app>REST-API-TEST</app> #应用名 类似于yml中的application-name
<ipAddr>192.168.128.1</ipAddr>
<vipAddress>rest-api-test</vipAddress>
<secureVipAddress>rest-api-test</secureVipAddress>
<status>UP</status>
<port enabled="true">9000</port>
<securePort enabled="false">443</securePort>
<homePageUrl>http://127.0.0.1:9000/</homePageUrl>
<statusPageUrl>http://127.0.0.1:9000/info</statusPageUrl>
<healthCheckUrl>http://127.0.0.1:9000/health</healthCheckUrl>
<dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
<name>MyOwn</name>
</dataCenterInfo>
</instance>
3.使用curl命令测试(注意:linux系统下才用cat ,windows系统下可以用type代替)
type ./rest-api-test.xml | curl -v -X POST -H "Content-type: application/xml" -d @- http://localhost:8761/eureka/apps/rest-api-test
终端将会输出类似以下内容:
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8761 (#0)
> POST /eureka/apps/rest-api-test HTTP/1.1
> Host: localhost:8761
> User-Agent: curl/7.62.0
> Accept: */*
> Content-type: application/xml
> Content-Length: 676
* upload completely sent off: 676 out of 676 bytes
< HTTP/1.1 204(代表报文中若干内容得到响应)
< Content-Type: application/xml
< Date: Mon, 27 Apr 2020 07:20:01 GMT
* Connection #0 to host localhost left intact
此时,查看Eureka Server首页,会发现微服务已经成功注册。
注销微服务实例
将上面注册的微服务实例注销
curl -v -X DELETE http://localhost:8761/eureka/apps/rest-api-test/SKY-20181224VZL(对应注册时的instanceId)
终端将会输出类似以下内容:
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8761 (#0)
> DELETE /eureka/apps/rest-api-test/SKY-20181224VZL HTTP/1.1
> Host: localhost:8761
> User-Agent: curl/7.62.0
> Accept: */*>
< HTTP/1.1 200
< Content-Type: application/xml
< Content-Length: 0
< Date: Mon, 27 Apr 2020 07:30:19 GMT
<* Connection #0 to host localhost left intact
本文多数摘自《Spring Cloud与Docker微服务架构实战》作者使用版本为Camden SR4版本 spring boot 1.4.3.RELEASE版本