Show List

Service Discovery Demo - Adding Eureka Server

Eureka is a REST based server that is used for storing the information about microservices and load balancing. Eureka server can be created as a Spring Boot application using Spring Cloud components.

Create "discovery" Eureka Server microservice (module)

Right click on the project and create a new module "discovery" similar to "order" and "payment" modules created earlier.

EurekaServerApplication :

Note the @EnableEurekaServer annotation to make this Spring Boot application a Eureka Server.
package com.springcloud.servicediscovery.eurekaserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication{
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}

}
pom.xml :
Here we are manually adding the dependency of eureka-server.
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>servicediscovery</artifactId>
<groupId>com.springcloud</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>discovery</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
</project>
application.yml
Here we are setting the property to notify it is not a client rather a server.

spring:
application:
name: eureka-discovery-server

server:
port: 9003

eureka:
client:
fetch-registry: false
register-with-eureka: false
banner.txt
 ,---.                              ,--.                  ,------.   ,--.
' .-' ,---. ,--.--. ,--. ,--. `--' ,---. ,---. | .-. \ `--' ,---. ,---. ,---. ,--. ,--. ,---. ,--.--. ,--. ,--.
`. `-. | .-. : | .--' \ `' / ,--. | .--' | .-. : | | \ : ,--. ( .-' | .--' | .-. | \ `' / | .-. : | .--' \ ' /
.-' | \ --. | | \ / | | \ `--. \ --. | '--' / | | .-' `) \ `--. ' '-' ' \ / \ --. | | \ '
`-----' `----' `--' `--' `--' `---' `----' `-------' `--' `----' `---' `---' `--' `----' `--' .-' /
`---'
When the application is run, Eureka service discovery dashboard can be viewed from the application port
"C:\Program Files\Java\jdk-11.0.15\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2\lib\idea_rt.jar=62243:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\mail2\Downloads\servicediscovery\discovery\target\classes;D:\.m2\repository\org\springframework\cloud\spring-cloud-starter-netflix-eureka-server\3.1.4\spring-cloud-starter-netflix-eureka-server-3.1.4.jar;D:\.m2\repository\org\springframework\cloud\spring-cloud-netflix-eureka-server\3.1.4\spring-cloud-netflix-eureka-server-3.1.4.jar;D:\.m2\repository\org\springframework\boot\spring-boot-starter-actuator\2.7.5\spring-boot-starter-actuator-2.7.5.jar;D:\.m2\repository\org\springframework\boot\spring-boot-actuator-autoconfigure\2.7.5\spring-boot-actuator-autoconfigure-2.7.5.jar;D:\.m2\repository\org\springframework\boot\spring-boot-actuator\2.7.5\spring-boot-actuator-2.7.5.jar;D:\.m2\repository\io\micrometer\micrometer-core\1.9.5\micrometer-core-1.9.5.jar;D:\.m2\repository\org\hdrhistogram\HdrHistogram\2.1.12\HdrHistogram-2.1.12.jar;D:\.m2\repository\org\latencyutils\LatencyUtils\2.0.3\LatencyUtils-2.0.3.jar;D:\.m2\repository\org\springframework\boot\spring-boot-starter-freemarker\2.7.5\spring-boot-starter-freemarker-2.7.5.jar;D:\.m2\repository\org\freemarker\freemarker\2.3.31\freemarker-2.3.31.jar;D:\.m2\repository\org\springframework\spring-context-support\5.3.23\spring-context-support-5.3.23.jar;D:\.m2\repository\org\springframework\cloud\spring-cloud-netflix-eureka-client\3.1.4\spring-cloud-netflix-eureka-client-3.1.4.jar;D:\.m2\repository\com\netflix\eureka\eureka-client\1.10.17\eureka-client-1.10.17.jar;D:\.m2\repository\com\netflix\netflix-commons\netflix-eventbus\0.3.0\netflix-eventbus-0.3.0.jar;D:\.m2\repository\com\netflix\netflix-commons\netflix-infix\0.3.0\netflix-infix-0.3.0.jar;D:\.m2\repository\commons-jxpath\commons-jxpath\1.3\commons-jxpath-1.3.jar;D:\.m2\repository\joda-time\joda-time\2.3\joda-time-2.3.jar;D:\.m2\repository\org\antlr\antlr-runtime\3.4\antlr-runtime-3.4.jar;D:\.m2\repository\org\antlr\stringtemplate\3.2.1\stringtemplate-3.2.1.jar;D:\.m2\repository\com\google\code\gson\gson\2.9.1\gson-2.9.1.jar;D:\.m2\repository\org\apache\commons\commons-math\2.2\commons-math-2.2.jar;D:\.m2\repository\com\thoughtworks\xstream\xstream\1.4.18\xstream-1.4.18.jar;D:\.m2\repository\io\github\x-stream\mxparser\1.2.2\mxparser-1.2.2.jar;D:\.m2\repository\xmlpull\xmlpull\1.1.3.1\xmlpull-1.1.3.1.jar;D:\.m2\repository\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;D:\.m2\repository\com\netflix\servo\servo-core\0.12.21\servo-core-0.12.21.jar;D:\.m2\repository\com\google\guava\guava\19.0\guava-19.0.jar;D:\.m2\repository\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;D:\.m2\repository\com\sun\jersey\contribs\jersey-apache-client4\1.19.1\jersey-apache-client4-1.19.1.jar;D:\.m2\repository\org\apache\httpcomponents\httpclient\4.5.13\httpclient-4.5.13.jar;D:\.m2\repository\org\apache\httpcomponents\httpcore\4.4.15\httpcore-4.4.15.jar;D:\.m2\repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar;D:\.m2\repository\commons-configuration\commons-configuration\1.10\commons-configuration-1.10.jar;D:\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\.m2\repository\com\google\inject\guice\4.1.0\guice-4.1.0.jar;D:\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.13.4\jackson-annotations-2.13.4.jar;D:\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.13.4\jackson-core-2.13.4.jar;D:\.m2\repository\org\codehaus\jettison\jettison\1.4.0\jettison-1.4.0.jar;D:\.m2\repository\com\sun\jersey\jersey-servlet\1.19.4\jersey-servlet-1.19.4.jar;D:\.m2\repository\com\sun\jersey\jersey-server\1.19.4\jersey-server-1.19.4.jar;D:\.m2\repository\com\sun\jersey\jersey-client\1.19.4\jersey-client-1.19.4.jar;D:\.m2\repository\com\netflix\eureka\eureka-core\1.10.17\eureka-core-1.10.17.jar;D:\.m2\repository\com\fasterxml\woodstox\woodstox-core\6.2.1\woodstox-core-6.2.1.jar;D:\.m2\repository\javax\inject\javax.inject\1\javax.inject-1.jar;D:\.m2\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-xml\2.13.4\jackson-dataformat-xml-2.13.4.jar;D:\.m2\repository\org\codehaus\woodstox\stax2-api\4.2.1\stax2-api-4.2.1.jar;D:\.m2\repository\org\springframework\cloud\spring-cloud-starter-loadbalancer\3.1.4\spring-cloud-starter-loadbalancer-3.1.4.jar;D:\.m2\repository\org\springframework\cloud\spring-cloud-loadbalancer\3.1.4\spring-cloud-loadbalancer-3.1.4.jar;D:\.m2\repository\io\projectreactor\reactor-core\3.4.24\reactor-core-3.4.24.jar;D:\.m2\repository\org\reactivestreams\reactive-streams\1.0.4\reactive-streams-1.0.4.jar;D:\.m2\repository\io\projectreactor\addons\reactor-extra\3.4.8\reactor-extra-3.4.8.jar;D:\.m2\repository\org\springframework\boot\spring-boot-starter-cache\2.7.5\spring-boot-starter-cache-2.7.5.jar;D:\.m2\repository\com\stoyanr\evictor\1.0.0\evictor-1.0.0.jar;D:\.m2\repository\org\glassfish\jaxb\jaxb-runtime\2.3.7\jaxb-runtime-2.3.7.jar;D:\.m2\repository\org\glassfish\jaxb\txw2\2.3.7\txw2-2.3.7.jar;D:\.m2\repository\com\sun\istack\istack-commons-runtime\3.0.12\istack-commons-runtime-3.0.12.jar;D:\.m2\repository\com\sun\activation\jakarta.activation\1.2.2\jakarta.activation-1.2.2.jar;D:\.m2\repository\org\springframework\boot\spring-boot-starter-data-jpa\2.7.5\spring-boot-starter-data-jpa-2.7.5.jar;D:\.m2\repository\org\springframework\boot\spring-boot-starter-aop\2.7.5\spring-boot-starter-aop-2.7.5.jar;D:\.m2\repository\org\springframework\spring-aop\5.3.23\spring-aop-5.3.23.jar;D:\.m2\repository\org\aspectj\aspectjweaver\1.9.7\aspectjweaver-1.9.7.jar;D:\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.7.5\spring-boot-starter-jdbc-2.7.5.jar;D:\.m2\repository\com\zaxxer\HikariCP\4.0.3\HikariCP-4.0.3.jar;D:\.m2\repository\org\springframework\spring-jdbc\5.3.23\spring-jdbc-5.3.23.jar;D:\.m2\repository\jakarta\transaction\jakarta.transaction-api\1.3.3\jakarta.transaction-api-1.3.3.jar;D:\.m2\repository\jakarta\persistence\jakarta.persistence-api\2.2.3\jakarta.persistence-api-2.2.3.jar;D:\.m2\repository\org\hibernate\hibernate-core\5.6.12.Final\hibernate-core-5.6.12.Final.jar;D:\.m2\repository\org\jboss\logging\jboss-logging\3.4.3.Final\jboss-logging-3.4.3.Final.jar;D:\.m2\repository\net\bytebuddy\byte-buddy\1.12.18\byte-buddy-1.12.18.jar;D:\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;D:\.m2\repository\org\jboss\jandex\2.4.2.Final\jandex-2.4.2.Final.jar;D:\.m2\repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;D:\.m2\repository\org\hibernate\common\hibernate-commons-annotations\5.1.2.Final\hibernate-commons-annotations-5.1.2.Final.jar;D:\.m2\repository\org\springframework\data\spring-data-jpa\2.7.5\spring-data-jpa-2.7.5.jar;D:\.m2\repository\org\springframework\data\spring-data-commons\2.7.5\spring-data-commons-2.7.5.jar;D:\.m2\repository\org\springframework\spring-orm\5.3.23\spring-orm-5.3.23.jar;D:\.m2\repository\org\springframework\spring-context\5.3.23\spring-context-5.3.23.jar;D:\.m2\repository\org\springframework\spring-tx\5.3.23\spring-tx-5.3.23.jar;D:\.m2\repository\org\springframework\spring-beans\5.3.23\spring-beans-5.3.23.jar;D:\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;D:\.m2\repository\org\springframework\spring-aspects\5.3.23\spring-aspects-5.3.23.jar;D:\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.7.5\spring-boot-starter-web-2.7.5.jar;D:\.m2\repository\org\springframework\boot\spring-boot-starter\2.7.5\spring-boot-starter-2.7.5.jar;D:\.m2\repository\org\springframework\boot\spring-boot\2.7.5\spring-boot-2.7.5.jar;D:\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.7.5\spring-boot-autoconfigure-2.7.5.jar;D:\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.7.5\spring-boot-starter-logging-2.7.5.jar;D:\.m2\repository\ch\qos\logback\logback-classic\1.2.11\logback-classic-1.2.11.jar;D:\.m2\repository\ch\qos\logback\logback-core\1.2.11\logback-core-1.2.11.jar;D:\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.17.2\log4j-to-slf4j-2.17.2.jar;D:\.m2\repository\org\apache\logging\log4j\log4j-api\2.17.2\log4j-api-2.17.2.jar;D:\.m2\repository\org\slf4j\jul-to-slf4j\1.7.36\jul-to-slf4j-1.7.36.jar;D:\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\.m2\repository\org\yaml\snakeyaml\1.30\snakeyaml-1.30.jar;D:\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.7.5\spring-boot-starter-json-2.7.5.jar;D:\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.13.4.2\jackson-databind-2.13.4.2.jar;D:\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.4\jackson-datatype-jdk8-2.13.4.jar;D:\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.4\jackson-datatype-jsr310-2.13.4.jar;D:\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.4\jackson-module-parameter-names-2.13.4.jar;D:\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.7.5\spring-boot-starter-tomcat-2.7.5.jar;D:\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.68\tomcat-embed-core-9.0.68.jar;D:\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.68\tomcat-embed-el-9.0.68.jar;D:\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.68\tomcat-embed-websocket-9.0.68.jar;D:\.m2\repository\org\springframework\spring-web\5.3.23\spring-web-5.3.23.jar;D:\.m2\repository\org\springframework\spring-webmvc\5.3.23\spring-webmvc-5.3.23.jar;D:\.m2\repository\org\springframework\spring-expression\5.3.23\spring-expression-5.3.23.jar;D:\.m2\repository\org\springframework\cloud\spring-cloud-starter\3.1.4\spring-cloud-starter-3.1.4.jar;D:\.m2\repository\org\springframework\cloud\spring-cloud-context\3.1.4\spring-cloud-context-3.1.4.jar;D:\.m2\repository\org\springframework\security\spring-security-crypto\5.7.4\spring-security-crypto-5.7.4.jar;D:\.m2\repository\org\springframework\cloud\spring-cloud-commons\3.1.4\spring-cloud-commons-3.1.4.jar;D:\.m2\repository\org\springframework\security\spring-security-rsa\1.0.11.RELEASE\spring-security-rsa-1.0.11.RELEASE.jar;D:\.m2\repository\org\bouncycastle\bcpkix-jdk15on\1.69\bcpkix-jdk15on-1.69.jar;D:\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.69\bcprov-jdk15on-1.69.jar;D:\.m2\repository\org\bouncycastle\bcutil-jdk15on\1.69\bcutil-jdk15on-1.69.jar;D:\.m2\repository\com\h2database\h2\2.1.214\h2-2.1.214.jar;D:\.m2\repository\org\projectlombok\lombok\1.18.24\lombok-1.18.24.jar;D:\.m2\repository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.3\jakarta.xml.bind-api-2.3.3.jar;D:\.m2\repository\jakarta\activation\jakarta.activation-api\1.2.2\jakarta.activation-api-1.2.2.jar;D:\.m2\repository\org\springframework\spring-core\5.3.23\spring-core-5.3.23.jar;D:\.m2\repository\org\springframework\spring-jcl\5.3.23\spring-jcl-5.3.23.jar com.springcloud.servicediscovery.eurekaserver.EurekaServerApplication ,---.                              ,--.                  ,------.   ,--.'   .-'   ,---.  ,--.--. ,--.  ,--. `--'  ,---.  ,---.    |  .-.  \  `--'  ,---.   ,---.  ,---.  ,--.  ,--.  ,---.  ,--.--. ,--. ,--.`.  `-.  | .-. : |  .--'  \  `'  /  ,--. | .--' | .-. :   |  |  \  : ,--. (  .-'  | .--' | .-. |  \  `'  /  | .-. : |  .--'  \  '  /.-'    | \   --. |  |      \    /   |  | \ `--. \   --.   |  '--'  / |  | .-'  `) \ `--. ' '-' '   \    /   \   --. |  |      \   '`-----'   `----' `--'       `--'    `--'  `---'  `----'   `-------'  `--' `----'   `---'  `---'     `--'     `----' `--'    .-'  /                                                                                                                            `---'2022-10-26 20:59:21.732  INFO 18824 --- [           main] c.s.s.e.EurekaServerApplication          : Starting EurekaServerApplication using Java 11.0.15 on sm15 with PID 18824 (C:\Users\mail2\Downloads\servicediscovery\discovery\target\classes started by mail2 in C:\Users\mail2\Downloads\servicediscovery)2022-10-26 20:59:21.740  INFO 18824 --- [           main] c.s.s.e.EurekaServerApplication          : No active profile set, falling back to 1 default profile: "default"2022-10-26 20:59:23.531  INFO 18824 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.2022-10-26 20:59:23.556  INFO 18824 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7 ms. Found 0 JPA repository interfaces.2022-10-26 20:59:24.080  INFO 18824 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=8415471e-e020-322b-98af-352408273e112022-10-26 20:59:25.485  INFO 18824 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9003 (http)2022-10-26 20:59:25.486  INFO 18824 --- [           main] o.a.catalina.core.AprLifecycleListener   : An older version [1.2.28] of the Apache Tomcat Native library is installed, while Tomcat recommends a minimum version of [1.2.30]2022-10-26 20:59:25.486  INFO 18824 --- [           main] o.a.catalina.core.AprLifecycleListener   : Loaded Apache Tomcat Native library [1.2.28] using APR version [1.7.0].2022-10-26 20:59:25.486  INFO 18824 --- [           main] o.a.catalina.core.AprLifecycleListener   : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].2022-10-26 20:59:25.486  INFO 18824 --- [           main] o.a.catalina.core.AprLifecycleListener   : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]2022-10-26 20:59:25.504  INFO 18824 --- [           main] o.a.catalina.core.AprLifecycleListener   : OpenSSL successfully initialized [OpenSSL 1.1.1k  25 Mar 2021]2022-10-26 20:59:25.522  INFO 18824 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]2022-10-26 20:59:25.522  INFO 18824 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.68]2022-10-26 20:59:25.766  INFO 18824 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext2022-10-26 20:59:25.766  INFO 18824 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3932 ms2022-10-26 20:59:26.565  INFO 18824 --- [           main] c.s.j.s.i.a.WebApplicationImpl           : Initiating Jersey application, version 'Jersey: 1.19.4 05/24/2017 03:20 PM'2022-10-26 20:59:26.658  INFO 18824 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON encoding codec LegacyJacksonJson2022-10-26 20:59:26.661  INFO 18824 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON decoding codec LegacyJacksonJson2022-10-26 20:59:26.901  INFO 18824 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using XML encoding codec XStreamXml2022-10-26 20:59:26.901  INFO 18824 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using XML decoding codec XStreamXml2022-10-26 20:59:27.581  INFO 18824 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...2022-10-26 20:59:27.972  INFO 18824 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.2022-10-26 20:59:28.091  INFO 18824 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]2022-10-26 20:59:28.232  INFO 18824 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.6.12.Final2022-10-26 20:59:28.686  INFO 18824 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}2022-10-26 20:59:28.906  INFO 18824 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect2022-10-26 20:59:29.221  INFO 18824 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]2022-10-26 20:59:29.233  INFO 18824 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'2022-10-26 20:59:29.295  WARN 18824 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning2022-10-26 20:59:30.972  INFO 18824 --- [           main] DiscoveryClientOptionalArgsConfiguration : Eureka HTTP Client uses Jersey2022-10-26 20:59:31.134  WARN 18824 --- [           main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. While this cache implementation is useful for development and tests, it's recommended to use Caffeine cache in production.You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.2022-10-26 20:59:31.164  INFO 18824 --- [           main] o.s.c.n.eureka.InstanceInfoFactory       : Setting initial instance status as: STARTING2022-10-26 20:59:31.239  INFO 18824 --- [           main] com.netflix.discovery.DiscoveryClient    : Initializing Eureka in region us-east-12022-10-26 20:59:31.240  INFO 18824 --- [           main] com.netflix.discovery.DiscoveryClient    : Client configured to neither register nor query for data.2022-10-26 20:59:31.260  INFO 18824 --- [           main] com.netflix.discovery.DiscoveryClient    : Discovery Client initialized at timestamp 1666832371254 with initial instances count: 02022-10-26 20:59:31.318  INFO 18824 --- [           main] c.n.eureka.DefaultEurekaServerContext    : Initializing ...2022-10-26 20:59:31.322  INFO 18824 --- [           main] c.n.eureka.cluster.PeerEurekaNodes       : Adding new peer nodes [http://localhost:8761/eureka/]2022-10-26 20:59:31.645  INFO 18824 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON encoding codec LegacyJacksonJson2022-10-26 20:59:31.646  INFO 18824 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON decoding codec LegacyJacksonJson2022-10-26 20:59:31.646  INFO 18824 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using XML encoding codec XStreamXml2022-10-26 20:59:31.646  INFO 18824 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using XML decoding codec XStreamXml2022-10-26 20:59:31.798  INFO 18824 --- [           main] c.n.eureka.cluster.PeerEurekaNodes       : Replica node URL:  http://localhost:8761/eureka/2022-10-26 20:59:31.817  INFO 18824 --- [           main] c.n.e.registry.AbstractInstanceRegistry  : Finished initializing remote region registries. All known remote regions: []2022-10-26 20:59:31.819  INFO 18824 --- [           main] c.n.eureka.DefaultEurekaServerContext    : Initialized2022-10-26 20:59:31.835  INFO 18824 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 1 endpoint(s) beneath base path '/actuator'2022-10-26 20:59:31.876  INFO 18824 --- [           main] o.s.c.n.e.s.EurekaServiceRegistry        : Registering application EUREKA-DISCOVERY-SERVER with eureka with status UP2022-10-26 20:59:31.896  INFO 18824 --- [       Thread-9] o.s.c.n.e.server.EurekaServerBootstrap   : isAws returned false2022-10-26 20:59:31.897  INFO 18824 --- [       Thread-9] o.s.c.n.e.server.EurekaServerBootstrap   : Initialized server context2022-10-26 20:59:31.897  INFO 18824 --- [       Thread-9] c.n.e.r.PeerAwareInstanceRegistryImpl    : Got 1 instances from neighboring DS node2022-10-26 20:59:31.897  INFO 18824 --- [       Thread-9] c.n.e.r.PeerAwareInstanceRegistryImpl    : Renew threshold is: 12022-10-26 20:59:31.898  INFO 18824 --- [       Thread-9] c.n.e.r.PeerAwareInstanceRegistryImpl    : Changing status to UP2022-10-26 20:59:31.911  INFO 18824 --- [       Thread-9] e.s.EurekaServerInitializerConfiguration : Started Eureka Server2022-10-26 20:59:31.917  INFO 18824 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9003 (http) with context path ''2022-10-26 20:59:31.918  INFO 18824 --- [           main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 90032022-10-26 20:59:32.377  INFO 18824 --- [           main] c.s.s.e.EurekaServerApplication          : Started EurekaServerApplication in 11.922 seconds (JVM running for 13.0)2022-10-26 20:59:48.307  INFO 18824 --- [nio-9003-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'2022-10-26 20:59:48.308  INFO 18824 --- [nio-9003-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'2022-10-26 20:59:48.310  INFO 18824 --- [nio-9003-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 2 ms2022-10-26 21:00:31.913  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 0ms2022-10-26 21:01:31.916  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 2ms2022-10-26 21:02:31.917  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 0ms2022-10-26 21:03:31.932  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 15ms2022-10-26 21:04:31.932  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 0ms2022-10-26 21:05:31.946  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 14ms2022-10-26 21:06:31.955  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 8ms2022-10-26 21:07:31.969  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 13ms2022-10-26 21:08:31.972  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 2ms2022-10-26 21:09:31.980  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 7ms2022-10-26 21:10:31.986  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 6ms2022-10-26 21:11:31.994  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 7ms2022-10-26 21:12:31.995  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 1ms2022-10-26 21:13:31.995  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 0ms2022-10-26 21:14:31.828  INFO 18824 --- [hresholdUpdater] c.n.e.r.PeerAwareInstanceRegistryImpl    : Current renewal threshold is : 12022-10-26 21:14:32.003  INFO 18824 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 7ms

http://localhost:9003/
Currently the dashboard is showing no instance registered. We are now going to register the "order" and "payment" service as the Eureka clients.

Register Eureka Clients

Add eureka client dependency in the POM files of services "order" and "payment"

pom.xml (order service)
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>servicediscovery</artifactId>
<groupId>com.springcloud</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>order</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
</project>
pom.xml (payment service)
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>servicediscovery</artifactId>
<groupId>com.springcloud</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>paymnt</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
</project>
In the application.yml file add Eureka client properties for both "order" and "payment"

application.yml (for order)
server:
port: 9001
spring:
application:
name: order-service
h2:
console:
enabled: true
eureka:
client:
service-url:
defaultZone: http://localhost:9003/eureka
fetch-registry: true
register-with-eureka: true
instance:
hostname: localhost
application.yml (for payment)
server:
port: 9002
spring:
application:
name: payment-service
h2:
console:
enabled: true
eureka:
client:
service-url:
defaultZone: http://localhost:9003/eureka
fetch-registry: true
register-with-eureka: true
instance:
hostname: localhost
Add @EnableEurekaClient annotation in the Spring Boot class of both the services.

OrderApplication.java
package com.springcloud.servicediscovery.order;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@EnableEurekaClient
@SpringBootApplication
public class OrderApplication {

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

}
PaymentApplication.java
package com.springcloud.servicediscovery.paymnt;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@EnableEurekaClient
@SpringBootApplication
public class PaymentApplication {

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

}
Restart the order and payment applications. They should now get registered with the Eureka server and show up on the dashboard:
Source code:

https://github.com/it-code-lab/spring-cloud-servicediscovery

    Leave a Comment


  • captcha text