使用Rest端点注册/注销微服务

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版本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值