Using Eureka as a registry using REST APIs

前端 未结 1 1358
再見小時候
再見小時候 2021-02-15 20:50

We have been using Eureka with our Spring Boot applications for few months now. We have enabled service lookup between applications using @DiscoveryClient annotatio

相关标签:
1条回答
  • 2021-02-15 21:21

    Finally, I have figured out how the cancel operation can be invoked using REST URLs of a Eureka server. This works for Spring Cloud Eureka server, but should also work for the Netflix Eureka server.

    The URL pattern for the cancel operation is as the following:

    DELETE http://eureka_host:eureka_port/eureka/apps/<appName>/<instanceId>
    

    This is how it is documented at the Eureka REST operations page, but there's very little clarity as to what <instanceId> was supposed to be. As per the documentation, <instanceId> is the hostname of the host that runs the Eureka client. That did not work (IP address or host name). I tried passing in the same value that the GET URL gave me (for example, 192.168.55.55) or localhost. That did not work either. I also tried passing in the instanceId value from the GET output (which would be the same as the value of eureka.instance.metadataMap.instanceId property). That too, didn't work. I literally had to try different combinations to find this out. The <instanceId> is the concatenation of the hostname and instance ID, separated by :. For example, 192.168.55.55:foo-app-some-random-str.

    Here's an example output of the GET operation listing the active instance registered with Eureka:

    <instance>
      <hostName>192.168.55.55</hostName>
      <app>FOO-APP</app>
      ...
      <metadata>
        <instanceId>foo-app-f4ea7b06fc03a05a06900713f7526a5d</instanceId>
      </metadata>
      ...
    </instance>
    

    In this case, the cancel cURL command would look like this:

    $ curl -X "DELETE" http://eureka_host:eureka_port/eureka/apps/FOO-APP/192.168.55.55:foo-app-f4ea7b06fc03a05a06900713f7526a5d
    

    That would de-register the instance as expected.

    That said, I must confess that I wasn't paying much attention to the Eureka server logs. When you register the Eureka client, the log printed out the fully qualified name of the instance (FOO-APP/192.168.55.55:foo-app-f4ea7b06fc03a05a06900713f7526a5d), which I could have used as my guess.

    I hope someone fixes this in the Eureka documentation.

    0 讨论(0)
提交回复
热议问题