I am trying out eureka with spring-boot. I successfully started eureka-server. It is running at localhost:8761.
Now I tried eureka-client. This is what the code is
import ch.qos.logback.classic.Logger;
import java.util.List;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class ServiceConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceConsumerApplication.class, args);
}
}
@RestController
class EurekaTestController {
private static Logger LOGGER = (Logger)LoggerFactory.getLogger(EurekaTestController.class);
@Autowired
DiscoveryClient discoveryClient;
@GetMapping("/service-instances/{applicationName}")
public List<ServiceInstance> getServiceInstance(@PathVariable("applicationName") String appName) {
List<ServiceInstance> serviceInstances = discoveryClient.getInstances(appName);
LOGGER.info("{}", serviceInstances);
return discoveryClient.getInstances(appName);
}
}
pom.xml is as below:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.shades</groupId>
<artifactId>service-consumer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>2020.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</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>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
</project>
properties defined for this project
server.port=8080
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8761/eureka}
spring.application.name=eureka-client
Now when I open http://localhost:8761/eureka in browser and I start above eureka-client app, then it shows app in UP status. But when I see in app's logs this is seen.
Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}, exception=Error while extracting response for type [class org.springframework.cloud.netflix.eureka.http.EurekaApplications] and content type [application/json;charset=UTF-8];
nested exception is org.springframework.http.converter.HttpMessageNotReadableException:
JSON parse error: Cannot deserialize instance of `java.util.ArrayList<com.netflix.appinfo.InstanceInfo>` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList<com.netflix.appinfo.InstanceInfo>` out of START_OBJECT token
at [Source: (PushbackInputStream); line: 1, column: 122] (through reference chain: com.netflix.discovery.converters.jackson.builder.ApplicationsJacksonBuilder["application"]->java.util.ArrayList[0]->com.netflix.discovery.shared.Application["instance"]) stacktrace=org.springframework.web.client.RestClientException: Error while extracting response for type [class org.springframework.cloud.netflix.eureka.http.EurekaApplications] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.util.ArrayList<com.netflix.appinfo.InstanceInfo>` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList<com.netflix.appinfo.InstanceInfo>` out of START_OBJECT token
at [Source: (PushbackInputStream); line: 1, column: 122] (through reference chain: com.netflix.discovery.converters.jackson.builder.ApplicationsJacksonBuilder["application"]->java.util.ArrayList[0]->com.netflix.discovery.shared.Application["instance"])
Later on this is also seen
2021-01-14 19:13:20.586 WARN 7970 --- [tbeatExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: Error while extracting response for type [class com.netflix.appinfo.InstanceInfo] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Root name 'timestamp' does not match expected ('instance') for type [simple type, class com.netflix.appinfo.InstanceInfo]; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Root name 'timestamp' does not match expected ('instance') for type [simple type, class com.netflix.appinfo.InstanceInfo]
at [Source: (PushbackInputStream); line: 1, column: 2] (through reference chain: com.netflix.appinfo.InstanceInfo["timestamp"])
2021-01-14 19:13:20.590 ERROR 7970 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EUREKA-CLIENT/192.168.43.183:eureka-client:8080 - was unable to send heartbeat!
What could this be?
Please help
I had a similar issue and managed to solve it by adding
@EnableEurekaClient
above SpintBootApplication in my client.