Eureka client registration request execution failure with status code 400.
Eureka server pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Eureka server application.properties: spring.application.name=name-service server.port=8761 eureka.client.register-with-eureka=false eureka.client.fetch-registry=false spring.security.user.name=root spring.security.user.password=root logging.level.com.netflix.eureka=DEBUG
Eureka server pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Eureka client application.properties:
logging.file.path=./
spring.application.name=file-service.
server.port=8000
eureka.client.serviceUrl.defaultZone=http://root:root@localhost:8761/eureka
Run Eureka server first, then run Eureka client on the same host.
Logs on Eureka server: 2021-03-04 17:32:40.066 INFO 9057 --- [ main] c.h.nameservice.NameServiceApplication : Started NameServiceApplication in 8.791 seconds (JVM running for 9.902) 2021-03-04 17:33:00.000 DEBUG 9057 --- [-CacheFillTimer] c.n.eureka.registry.ResponseCacheImpl : Updating the client cache from response cache 2021-03-04 17:33:19.372 INFO 9057 --- [nio-8761-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2021-03-04 17:33:19.372 INFO 9057 --- [nio-8761-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2021-03-04 17:33:19.373 INFO 9057 --- [nio-8761-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms 2021-03-04 17:33:19.651 DEBUG 9057 --- [nio-8761-exec-1] c.n.e.registry.AbstractInstanceRegistry : Fetching applications registry with remote regions: false, Regions argument [] 2021-03-04 17:33:19.663 DEBUG 9057 --- [nio-8761-exec-1] c.n.eureka.registry.ResponseCacheImpl : New application cache entry {name=ALL_APPS, type=Application, format=JSON} with apps hashcode 2021-03-04 17:33:20.115 DEBUG 9057 --- [nio-8761-exec-2] c.n.e.resources.ApplicationResource : Registering instance 172.16.0.12:file-service. :8000 (replication=null) 2021-03-04 17:33:30.001 DEBUG 9057 --- [-CacheFillTimer] c.n.eureka.registry.ResponseCacheImpl : Updating the client cache from response cache 2021-03-04 17:33:30.001 DEBUG 9057 --- [-CacheFillTimer] c.n.eureka.registry.ResponseCacheImpl : Updating the client cache from response cache for key : Application ALL_APPS V2 JSON 2021-03-04 17:33:30.449 DEBUG 9057 --- [nio-8761-exec-3] c.n.e.resources.ApplicationResource : Registering instance 172.16.0.12:file-service. :8000 (replication=null) 2021-03-04 17:33:30.567 WARN 9057 --- [nio-8761-exec-4] c.n.e.registry.AbstractInstanceRegistry : DS: Registry: cancel failed because Lease is not registered for: FILE-SERVICE./172.16.0.12:file-service. :8000 2021-03-04 17:33:30.568 INFO 9057 --- [nio-8761-exec-4] c.n.eureka.resources.InstanceResource : Not Found (Cancel): FILE-SERVICE. - 172.16.0.12:file-service. :8000 2021-03-04 17:33:39.979 INFO 9057 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms 2021-03-04 17:33:39.979 DEBUG 9057 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task 2021-03-04 17:33:39.979 DEBUG 9057 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : DS: lease expiration is currently disabled. 2021-03-04 17:34:00.002 DEBUG 9057 --- [-CacheFillTimer] c.n.eureka.registry.ResponseCacheImpl : Updating the client cache from response cache 2021-03-04 17:34:00.002 DEBUG 9057 --- [-CacheFillTimer] c.n.eureka.registry.ResponseCacheImpl : Updating the client cache from response cache for key : Application ALL_APPS V2 JSON
Logs on Eureka client: 2021-03-04 17:33:18.993 INFO 9224 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1 2021-03-04 17:33:19.002 INFO 9224 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration 2021-03-04 17:33:19.043 INFO 9224 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false 2021-03-04 17:33:19.043 INFO 9224 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null 2021-03-04 17:33:19.043 INFO 9224 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false 2021-03-04 17:33:19.043 INFO 9224 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false 2021-03-04 17:33:19.043 INFO 9224 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true 2021-03-04 17:33:19.043 INFO 9224 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true 2021-03-04 17:33:19.043 INFO 9224 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server 2021-03-04 17:33:19.721 INFO 9224 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200 2021-03-04 17:33:19.725 INFO 9224 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30 2021-03-04 17:33:19.731 INFO 9224 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4 2021-03-04 17:33:19.738 INFO 9224 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1614850399736 with initial instances count: 0 2021-03-04 17:33:19.740 INFO 9224 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application FILE-SERVICE. with eureka with status UP 2021-03-04 17:33:19.740 INFO 9224 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1614850399740, current=UP, previous=STARTING] 2021-03-04 17:33:19.749 INFO 9224 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_FILE-SERVICE. /172.16.0.12:file-service. :8000: registering service... 2021-03-04 17:33:19.815 INFO 9224 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8000 (http) with context path '' 2021-03-04 17:33:19.816 INFO 9224 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8000 2021-03-04 17:33:19.897 INFO 9224 --- [ main] c.h.fileservice.FileServiceApplication : Started FileServiceApplication in 6.693 seconds (JVM running for 7.472) 2021-03-04 17:33:20.119 WARN 9224 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failure with status code 400; retrying on another server if available 2021-03-04 17:33:20.125 WARN 9224 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_FILE-SERVICE. /172.16.0.12:file-service. :8000 - registration failed Cannot execute request on any known server
It seems client sends wrong format registration data to server. Is there any config on client I missing?
Comment From: crytoskyx
I didn't get a valid solution after overwhelmingly searching from internet. Then I began debugging it by myself. When tracing into com.netflix.eureka.resources.ApplicationResource.addInstance() method, I found the client's service name is "file-service. ", not "file-service" I expected. The root cause was the client's service name was tailed with a space char " ". What a big trap! It's so difficult finding that. To avoid this kind of problems, I suggest add eureka client's naming specification to the official documents.
Comment From: OlgaMaciaszek
We do not modify the service names - the service must have been named like this by the client service authors.