Skip to content

Commit f5bef19

Browse files
authored
Merge pull request #7 from dksifoua/feature/6-setup-discovery-server
Setup netflix eureka service discovery
2 parents e8d66ec + ba276ec commit f5bef19

File tree

18 files changed

+218
-10
lines changed

18 files changed

+218
-10
lines changed

.github/workflows/eureka.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: eureka-server
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
- feature/**
9+
pull_request:
10+
branches:
11+
- main
12+
- develop
13+
- feature/**
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Setup Java
21+
uses: actions/setup-java@v4
22+
with:
23+
distribution: oracle
24+
java-version: 21
25+
- name: Setup Task
26+
uses: arduino/setup-task@v2
27+
with:
28+
version: 3.x
29+
repo-token: ${{ secrets.GH_TOKEN }}
30+
- name: Test eureka server
31+
run: task eureka:test

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ Event driven microservice-based c2c ecommerce platform
44

55
[![](https://github.com/dksifoua/eshop/actions/workflows/eshop.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/eshop.yaml)
66

7-
[![](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml)
87
[![](https://github.com/dksifoua/eshop/actions/workflows/gateway.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/gateway.yaml)
8+
[![](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml)
9+
[![](https://github.com/dksifoua/eshop/actions/workflows/eureka.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/eureka.yaml)

Taskfile.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ version: 3
33
includes:
44
catalog:
55
taskfile: ./catalog-service/Taskfile.yaml
6+
eureka:
7+
taskfile: ./eureka-server/Taskfile.yaml
68
gateway:
79
taskfile: ./api-gateway/Taskfile.yaml
810

@@ -17,7 +19,9 @@ tasks:
1719
silent: true
1820
test:
1921
desc: Test all projects
20-
cmd: ./gradlew test --parallel
22+
cmds:
23+
- task: clean
24+
- ./gradlew test --parallel
2125
silent: true
2226

2327
gradle:stop:

api-gateway/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies {
2727
}
2828

2929
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
30+
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
3031
developmentOnly 'org.springframework.boot:spring-boot-devtools'
3132
testImplementation 'org.springframework.boot:spring-boot-starter-test'
3233
testImplementation 'io.projectreactor:reactor-test'

api-gateway/src/main/resources/application.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
server:
22
port: 8080
33

4+
eureka:
5+
client:
6+
service-url:
7+
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
8+
49
spring:
510
application:
611
name: api-gateway

api-gateway/src/test/java/io/dksifoua/eshop/gateway/ApiGatewayApplicationTests.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
import org.junit.jupiter.api.Test;
44
import org.springframework.boot.test.context.SpringBootTest;
5+
import org.springframework.test.context.TestPropertySource;
56

67
@SpringBootTest
8+
@TestPropertySource(properties = {
9+
"eureka.client.enabled=false",
10+
"eureka.client.register-with-eureka=false",
11+
"eureka.client.fetch-registry=false"
12+
})
713
class ApiGatewayApplicationTests {
814

9-
@Test
10-
void contextLoads() {
11-
}
15+
@Test
16+
void contextLoads() {
17+
}
1218

1319
}

catalog-service/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ plugins {
44
id 'io.spring.dependency-management' version '1.1.6'
55
}
66

7+
ext {
8+
springCloudVersion = "2023.0.3"
9+
}
10+
711
group = 'io.dksifoua.eshop'
812
version = '0.0.1-SNAPSHOT'
913

@@ -26,6 +30,7 @@ repositories {
2630
dependencies {
2731
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
2832
implementation 'org.springframework.boot:spring-boot-starter-webflux'
33+
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
2934
compileOnly 'org.projectlombok:lombok'
3035
developmentOnly 'org.springframework.boot:spring-boot-devtools'
3136
developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
@@ -38,6 +43,12 @@ dependencies {
3843
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
3944
}
4045

46+
dependencyManagement {
47+
imports {
48+
mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
49+
}
50+
}
51+
4152
tasks.named('test') {
4253
useJUnitPlatform()
4354
}

catalog-service/src/main/java/io/dksifoua/eshop/catalog/handler/IndexHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
public class IndexHandler {
99

1010
public Mono<ServerResponse> index() {
11-
return ServerResponse.ok().body(Mono.just("Welcome to eshop product category service!"), String.class);
11+
String responseData = "Welcome to eshop product category service!";
12+
return ServerResponse.ok().body(Mono.just(responseData), String.class);
1213
}
1314
}

catalog-service/src/main/resources/application.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
app:
22
base-path: /api/v1/catalog
33

4+
eureka:
5+
client:
6+
service-url:
7+
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
8+
49
server:
510
port: 8081
611

catalog-service/src/test/java/io/dksifoua/eshop/catalog/CatalogServiceApplicationTests.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
import org.junit.jupiter.api.Test;
44
import org.springframework.boot.test.context.SpringBootTest;
55
import org.springframework.context.annotation.Import;
6+
import org.springframework.test.context.TestPropertySource;
67

78
@Import(TestcontainersConfiguration.class)
89
@SpringBootTest
10+
@TestPropertySource(properties = {
11+
"eureka.client.enabled=false",
12+
"eureka.client.register-with-eureka=false",
13+
"eureka.client.fetch-registry=false"
14+
})
915
class CatalogServiceApplicationTests {
1016

11-
@Test
12-
void contextLoads() {
13-
}
17+
@Test
18+
void contextLoads() {
19+
assert true;
20+
}
1421

1522
}

eureka-server/.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
HELP.md
2+
.gradle
3+
build/
4+
!gradle/wrapper/gradle-wrapper.jar
5+
!**/src/main/**/build/
6+
!**/src/test/**/build/
7+
8+
### STS ###
9+
.apt_generated
10+
.classpath
11+
.factorypath
12+
.project
13+
.settings
14+
.springBeans
15+
.sts4-cache
16+
bin/
17+
!**/src/main/**/bin/
18+
!**/src/test/**/bin/
19+
20+
### IntelliJ IDEA ###
21+
.idea
22+
*.iws
23+
*.iml
24+
*.ipr
25+
out/
26+
!**/src/main/**/out/
27+
!**/src/test/**/out/
28+
29+
### NetBeans ###
30+
/nbproject/private/
31+
/nbbuild/
32+
/dist/
33+
/nbdist/
34+
/.nb-gradle/
35+
36+
### VS Code ###
37+
.vscode/

eureka-server/Taskfile.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: 3
2+
3+
tasks:
4+
clean:
5+
desc: Clean eureka server build
6+
cmd: ./gradlew :eureka-server:clean
7+
silent: true
8+
9+
run:
10+
desc: Run netflix eureka server
11+
cmd: ./gradlew :eureka-server:bootRun
12+
silent: true
13+
14+
test:
15+
desc: Test netflix eureka server
16+
cmds:
17+
- task: clean
18+
- ./gradlew :eureka-server:test
19+
silent: true

eureka-server/build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
plugins {
2+
id 'java'
3+
id 'org.springframework.boot' version '3.3.3'
4+
id 'io.spring.dependency-management' version '1.1.6'
5+
}
6+
7+
group = 'io.dksifoua.eshop'
8+
version = '0.0.1-SNAPSHOT'
9+
10+
java {
11+
toolchain {
12+
languageVersion = JavaLanguageVersion.of(21)
13+
}
14+
}
15+
16+
repositories {
17+
mavenCentral()
18+
}
19+
20+
ext {
21+
set('springCloudVersion', "2023.0.3")
22+
}
23+
24+
dependencies {
25+
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
26+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
27+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
28+
}
29+
30+
dependencyManagement {
31+
imports {
32+
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
33+
}
34+
}
35+
36+
tasks.named('test') {
37+
useJUnitPlatform()
38+
}

eureka-server/settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'eureka'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.dksifoua.eshop.eureka;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
6+
7+
@SpringBootApplication
8+
@EnableEurekaServer
9+
public class EurekaServerApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(EurekaServerApplication.class, args);
13+
}
14+
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eureka:
2+
client:
3+
fetch-registry: false
4+
register-with-eureka: false
5+
6+
server:
7+
port: 8761
8+
9+
spring:
10+
application:
11+
name: eureka-server
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.dksifoua.eshop.eureka;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class EurekaServerApplicationTests {
8+
9+
@Test
10+
void contextLoads() {
11+
assert true;
12+
}
13+
14+
}

settings.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
rootProject.name = 'eshop'
22

33
include('api-gateway')
4-
include('catalog-service')
4+
include('catalog-service')
5+
include('eureka-server')

0 commit comments

Comments
 (0)