Using Eureka as a registry using the REST API

We have been using Eureka with our Spring download applications for several months. We have activated the search for services between applications using the @DiscoveryClient annotations. Registration, renewal, and deregistration work as expected.

Recently, we came across a scenario in which we have a component of a non-Java application (written in C ++) that provides three REST service endpoints that many of our Spring Boot Java applications will use. We are trying to find out if the C ++ component can use the Eureka REST API to register when it appears, so Spring Boot Java applications can do a regular search through Eureka to contact the C ++ component.

Since I cannot use the Eureka client in C ++ components (obviously), I started testing the direct REST APIs (as described here ) using Postman. Registration worked without any problems sending the JSON payload using the POST method in http: // eurekaserver: 8761 / eureka / apps / FOO-APP (with instanceId = 1111 and hostName = foo-app). I can request http: // eurekaserver: 8761 / eureka / apps and can see that the FOO-APP is listed there as expected.

However, when I try to perform a cancel operation using the DELETE method, http: // eurekaserver: 8761 / eureka / apps / FOO-APP / 1111 or http: // eurekaserver: 8761 / eureka / apps / FOO-APP / foo-app I get a 404 error.

With instanceId:

 { "timestamp": 1447479397996, "status": 404, "error": "Not Found", "message": "Not Found", "path": "/eureka/apps/FOO-APP/1111" } 

OR (same result for hostName):

 { "timestamp": 1447479397996, "status": 404, "error": "Not Found", "message": "Not Found", "path": "/eureka/apps/FOO-APP/foo-app" } 

I tried different combinations, but I can not do this work. I have a feeling that I'm missing something obvious - maybe something small. Any help on this would be appreciated.

PS: The Eureka REST documentation for endpoints mentions "v2" in the URL. However, this does not work in my case. Registration (which works for me) does not use "v2" as described above. If someone can confirm this, it will also be useful. It seems that is not enough.

+7
source share
1 answer

Finally, I found out how to activate the cancel operation using the Eureka server REST URLs. This works for the Spring Cloud Eureka server, but should also work on the Netflix Eureka server.

The URL pattern for the cancel operation is as follows:

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

This is how it is described on the Eureka REST page, but there is very little clarity as to what should have been <instanceId> . According to the documentation, <instanceId> is the host name of the host on which the Eureka client is running. This helped not work (IP address or hostname). I tried to pass the same value that gave me a GET URL (e.g. 192.168.55.55) or localhost . That didn't work either. I also tried passing the value of instanceId from the output of the GET (which will be the same as the value of the eureka.instance.metadataMap.instanceId property). That didn't work either. I literally had to try different combinations to find out. <instanceId> is a concatenation of the host name and instance ID, separated by the symbol : For example, 192.168.55.55:foo-app-some-random-str .

Here is an example of the output of a GET operation indicating the active instance registered in 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 will look like this:

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

This will uninstall the instance as expected.

Having said that, I must admit that I did not pay much attention to the Eureka server logs. When you register an Eureka client, the log prints the full name of the instance ( FOO-APP/192.168.55.55:foo-app-f4ea7b06fc03a05a06900713f7526a5d ), which I could use as my guess.

I hope someone fixes this in the Eureka documentation .

+12
source

Source: https://habr.com/ru/post/1235942/


All Articles