Skip to content

Commit

Permalink
Setup netflix eureka service discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
dksifoua committed Sep 13, 2024
1 parent e8d66ec commit 948fc10
Show file tree
Hide file tree
Showing 18 changed files with 218 additions and 10 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/eureka.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: eureka

on:
push:
branches:
- main
- develop
- feature/**
pull_request:
branches:
- main
- develop
- feature/**

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: oracle
java-version: 21
- name: Setup Task
uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GH_TOKEN }}
- name: Test eureka server
run: task eureka:test
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Event driven microservice-based c2c ecommerce platform

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

[![](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml)
[![](https://github.com/dksifoua/eshop/actions/workflows/gateway.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/gateway.yaml)
[![](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml)
[![](https://github.com/dksifoua/eshop/actions/workflows/eureka.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/eureka.yaml)
6 changes: 5 additions & 1 deletion Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ version: 3
includes:
catalog:
taskfile: ./catalog-service/Taskfile.yaml
eureka:
taskfile: ./eureka-server/Taskfile.yaml
gateway:
taskfile: ./api-gateway/Taskfile.yaml

Expand All @@ -17,7 +19,9 @@ tasks:
silent: true
test:
desc: Test all projects
cmd: ./gradlew test --parallel
cmds:
- task: clean
- ./gradlew test --parallel
silent: true

gradle:stop:
Expand Down
1 change: 1 addition & 0 deletions api-gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
}

implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
Expand Down
5 changes: 5 additions & 0 deletions api-gateway/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
server:
port: 8080

eureka:
client:
service-url:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}

spring:
application:
name: api-gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;

@SpringBootTest
@TestPropertySource(properties = {
"eureka.client.enabled=false",
"eureka.client.register-with-eureka=false",
"eureka.client.fetch-registry=false"
})
class ApiGatewayApplicationTests {

@Test
void contextLoads() {
}
@Test
void contextLoads() {
}

}
11 changes: 11 additions & 0 deletions catalog-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ plugins {
id 'io.spring.dependency-management' version '1.1.6'
}

ext {
springCloudVersion = "2023.0.3"
}

group = 'io.dksifoua.eshop'
version = '0.0.1-SNAPSHOT'

Expand All @@ -26,6 +30,7 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
Expand All @@ -38,6 +43,12 @@ dependencies {
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
}
}

tasks.named('test') {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class IndexHandler {

public Mono<ServerResponse> index() {
return ServerResponse.ok().body(Mono.just("Welcome to eshop product category service!"), String.class);
String responseData = "Welcome to eshop product category service!";
return ServerResponse.ok().body(Mono.just(responseData), String.class);
}
}
5 changes: 5 additions & 0 deletions catalog-service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
app:
base-path: /api/v1/catalog

eureka:
client:
service-url:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}

server:
port: 8081

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.TestPropertySource;

@Import(TestcontainersConfiguration.class)
@SpringBootTest
@TestPropertySource(properties = {
"eureka.client.enabled=false",
"eureka.client.register-with-eureka=false",
"eureka.client.fetch-registry=false"
})
class CatalogServiceApplicationTests {

@Test
void contextLoads() {
}
@Test
void contextLoads() {
assert true;
}

}
37 changes: 37 additions & 0 deletions eureka-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
19 changes: 19 additions & 0 deletions eureka-server/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 3

tasks:
clean:
desc: Clean eureka server build
cmd: ./gradlew :eureka-server:clean
silent: true

run:
desc: Run netflix eureka server
cmd: ./gradlew :eureka-server:bootRun
silent: true

test:
desc: Test netflix eureka server
cmds:
- task: clean
- ./gradlew :eureka-server:test
silent: true
38 changes: 38 additions & 0 deletions eureka-server/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
}

group = 'io.dksifoua.eshop'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

repositories {
mavenCentral()
}

ext {
set('springCloudVersion', "2023.0.3")
}

dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

tasks.named('test') {
useJUnitPlatform()
}
1 change: 1 addition & 0 deletions eureka-server/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'eureka'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.dksifoua.eshop.eureka;

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

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

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

}
11 changes: 11 additions & 0 deletions eureka-server/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eureka:
client:
fetch-registry: false
register-with-eureka: false

server:
port: 8761

spring:
application:
name: eureka-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.dksifoua.eshop.eureka;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class EurekaServerApplicationTests {

@Test
void contextLoads() {
assert true;
}

}
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
rootProject.name = 'eshop'

include('api-gateway')
include('catalog-service')
include('catalog-service')
include('eureka-server')

0 comments on commit 948fc10

Please sign in to comment.