Spring-cloud-netflix: Registering a service with 2 local Eureka Server instances with Java 9.0.4/Spring v2.0.0 fails

Created on 3 Mar 2018  路  8Comments  路  Source: spring-cloud/spring-cloud-netflix

Possibly relevant dependencies:

spring-cloud-starter-netflix-eureka-server\2.0.0.BUILD-SNAPSHOT
com.netflix.eureka\eureka-core\1.8.6
com.netflix.eureka\eureka-client\1.8.6
spring-cloud-netflix-eureka-client\2.0.0.BUILD-SNAPSHOT
spring-cloud-netflix-core\2.0.0.BUILD-SNAPSHOT

I have my 2 Eureka Server names defined in my hosts file:

127.0.0.1   peer1
127.0.0.1   peer2

My Eureka Server is defined as such:

@SpringBootApplication
@EnableEurekaServer
public class SpringMicroservicesEurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringMicroservicesEurekaServerApplication.class, args);
    }
}

The 2 related server resources

application-peer1.yml

server:
  port: 8761
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url: 
      defaultZone: http://peer2:8762  # Where's my buddy?
  instance:
    hostname: peer1
    health-check-url: http://peer1:8761/actuator/health
    status-page-url: http://peer1:8761/actuator/status
    lease-renewal-interval-in-seconds: 5

application-peer2.yml

server:
  port: 8762
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url: 
      defaultZone: http://peer1:8761
  instance:
    hostname: peer2
    health-check-url: http://peer2:8762/actuator/health
    status-page-url: http://peer2:8762/actuator/health
    lease-renewal-interval-in-seconds: 5

My service is defined thusly

@SpringBootApplication
@EnableEurekaClient
public class SpringMicroservicesEurekaClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringMicroservicesEurekaClientApplication.class, args);
    }
}

Its 2 resource files

bootstrap.yml

[intentionally left blank]

application.yml

eureka:
  instance:
    leaseRenewalIntervalInSeconds: 1
    leaseExpirationDurationInSeconds: 2
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/
spring:    
  application:
    name: MyStupidService

logging:
  level:
    com.oreilly.cloud: DEBUG

The service hits the server, but fails to register:

DS: Registry: cancel failed because Lease is not registered for: MYSTUPIDSERVICE/192.168.0.105:MyStupidService
Not Found (Cancel): MYSTUPIDSERVICE - 192.168.0.105:MyStupidService

This may also be relevant. Here are the client logs:

Registering application MyStupidService with eureka with status UP
Saw local status change event StatusChangeEvent [timestamp=1520114947579, current=UP, previous=STARTING]
DiscoveryClient_MYSTUPIDSERVICE/192.168.0.105:MyStupidService: registering service...
DiscoveryClient_MYSTUPIDSERVICE/192.168.0.105:MyStupidService - registration status: 204
Started SpringMicroservicesEurekaClientApplication in 5.074 seconds (JVM running for 6.373)
Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@6eafb10e: startup date [Sat Mar 03 17:09:04 EST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@4c2cc639
Unregistering application MyStupidService with eureka with status DOWN
Saw local status change event StatusChangeEvent [timestamp=1520114947606, current=DOWN, previous=UP]
DiscoveryClient_MYSTUPIDSERVICE/192.168.0.105:MyStupidService: registering service...
Stopping beans in phase 0
Shutting down DiscoveryClient ...
Unregistering ...
DiscoveryClient_MYSTUPIDSERVICE/192.168.0.105:MyStupidService - registration status: 204
DiscoveryClient_MYSTUPIDSERVICE/192.168.0.105:MyStupidService - deregister  status: 200
Completed shut down of DiscoveryClient

The github repo is at:
https://github.com/jclevine/eureka_server_client_test


This seems to work for Spring Boot v1.5.9, so it may very well be a bug in v2.0.0.

Most helpful comment

My guess is that this is happening because your application is finished running. Maybe you are expecting your client to run as a web app? If so you will need to add

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

All 8 comments

Can you get your app back in a state that 2.0.0 fails. You made changes including moving back to Edgware.

@spencergibb If you go back to this commit, it should fail as shown above.

My guess is that this is happening because your application is finished running. Maybe you are expecting your client to run as a web app? If so you will need to add

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

Weird. I wonder why it works without that in the earlier version of Spring Boot. I'll give this a shot and see if it works.

Weird. I wonder why it works without that in the earlier version of Spring Boot. I'll give this a shot and see if it works.

That should work, because I faced the same problem, Spring Boot 2+ versions explicitly needed Web starter too , earlier, just Eureka Discovery was just enough

Closing this due to inactivity. Please re-open if there's more to discuss.

Iam having above issuse instance cancelled after registring instance plz give solution anyone

@RADHAPANDIKUNTA please open a new issue and provide a complete, minimal, verifiable sample that reproduces the problem. It should be available as a GitHub (or similar) project or attached to the issue as a zip file.

Was this page helpful?
0 / 5 - 0 ratings