feat(Tracer Bullet)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# Temp / Ping-Service
|
||||
|
||||
## ⚠️ Wichtiger Hinweis
|
||||
|
||||
Dieses Modul (`:temp:ping-service`) ist ein **temporärer Service** ausschließlich für Testzwecke. Seine einzige Aufgabe ist die Validierung der technischen Infrastruktur im Rahmen des **"Tracer Bullet"-Szenarios**.
|
||||
|
||||
Nachdem der End-to-End-Test erfolgreich war, sollte dieses Modul in der `settings.gradle.kts` wieder deaktiviert oder vollständig entfernt werden.
|
||||
|
||||
## 1. Überblick
|
||||
|
||||
Der `ping-service` ist ein minimaler Spring Boot Microservice, der beweisen soll, dass die grundlegende Service-Architektur funktioniert. Dies beinhaltet:
|
||||
* Korrekte Konfiguration und Start einer Spring Boot Anwendung.
|
||||
* Bereitstellung eines einfachen REST-Endpunkts.
|
||||
* Einbindung in die Gradle-Build-Logik.
|
||||
* Integration in das Test-Framework.
|
||||
|
||||
## 2. Funktionalität
|
||||
|
||||
Der Service stellt einen einzigen HTTP-Endpunkt zur Verfügung:
|
||||
|
||||
* **`GET /ping`**
|
||||
* **Antwort:** Gibt ein einfaches JSON-Objekt zurück, das den erfolgreichen Aufruf bestätigt.
|
||||
* **Beispiel-Antwort-Body:**
|
||||
```json
|
||||
{
|
||||
"status": "pong"
|
||||
}
|
||||
```
|
||||
|
||||
## 3. Konfiguration
|
||||
|
||||
Die Konfiguration des Services erfolgt über die `application.yml`-Datei.
|
||||
|
||||
* **`spring.application.name`**: `ping-service`
|
||||
* **`server.port`**: `8082`
|
||||
|
||||
## 4. Wie man den Service startet
|
||||
|
||||
Um den Service lokal zu starten, führen Sie den folgenden Gradle-Befehl aus:
|
||||
|
||||
```bash
|
||||
./gradlew :temp:ping-service:bootRun
|
||||
```
|
||||
|
||||
## 5. Wie man den Service testet
|
||||
|
||||
Nach dem Start können Sie die Funktionalität mit einem einfachen curl-Befehl überprüfen:
|
||||
|
||||
```bash
|
||||
curl http://localhost:8082/ping
|
||||
```
|
||||
@@ -0,0 +1,17 @@
|
||||
FROM openjdk:17-jre-slim
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the ping-service JAR file
|
||||
COPY temp/ping-service/build/libs/*.jar app.jar
|
||||
|
||||
# Expose port (will be assigned dynamically by Spring Boot)
|
||||
EXPOSE 8080
|
||||
|
||||
# Add health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=20s --retries=3 \
|
||||
CMD curl -f http://localhost:8080/ping || exit 1
|
||||
|
||||
# Run the application
|
||||
ENTRYPOINT ["java", "-jar", "app.jar"]
|
||||
@@ -0,0 +1,33 @@
|
||||
// Simple Spring Boot ping service for testing microservice architecture
|
||||
plugins {
|
||||
alias(libs.plugins.kotlin.jvm)
|
||||
alias(libs.plugins.kotlin.spring)
|
||||
alias(libs.plugins.spring.boot)
|
||||
alias(libs.plugins.spring.dependencyManagement)
|
||||
}
|
||||
|
||||
// Configure the main class for the executable JAR
|
||||
springBoot {
|
||||
mainClass.set("at.mocode.temp.pingservice.PingServiceApplicationKt")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Ensure all versions come from the central BOM
|
||||
implementation(platform(projects.platform.platformBom))
|
||||
// Provide common dependencies
|
||||
implementation(projects.platform.platformDependencies)
|
||||
|
||||
// Spring Boot Web starter for REST endpoints
|
||||
implementation(libs.spring.boot.starter.web)
|
||||
|
||||
// Spring Boot Actuator for health checks
|
||||
implementation(libs.spring.boot.starter.actuator)
|
||||
|
||||
// Spring Cloud Consul for service discovery
|
||||
implementation(libs.spring.cloud.starter.consul.discovery)
|
||||
|
||||
// Testing dependencies
|
||||
testImplementation(projects.platform.platformTesting)
|
||||
testImplementation(libs.bundles.testing.jvm)
|
||||
testImplementation(libs.spring.boot.starter.test)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package at.mocode.temp.pingservice
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
class PingController {
|
||||
|
||||
@GetMapping("/ping")
|
||||
fun ping(): Map<String, String> {
|
||||
return mapOf("status" to "pong")
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package at.mocode.temp.pingservice
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.runApplication
|
||||
|
||||
@SpringBootApplication
|
||||
class PingServiceApplication
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<PingServiceApplication>(*args)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
spring:
|
||||
application:
|
||||
name: ping-service
|
||||
cloud:
|
||||
consul:
|
||||
host: localhost
|
||||
port: 8500
|
||||
discovery:
|
||||
register: true
|
||||
health-check-path: /actuator/health
|
||||
health-check-interval: 10s
|
||||
|
||||
server:
|
||||
port: 8082
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
@@ -0,0 +1,23 @@
|
||||
package at.mocode.temp.pingservice
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
||||
import org.springframework.test.web.servlet.MockMvc
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.*
|
||||
|
||||
@WebMvcTest(PingController::class)
|
||||
class PingControllerTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var mockMvc: MockMvc
|
||||
|
||||
@Test
|
||||
fun `ping endpoint should return pong status`() {
|
||||
mockMvc.perform(get("/ping"))
|
||||
.andExpect(status().isOk)
|
||||
.andExpect(content().contentType("application/json"))
|
||||
.andExpect(jsonPath("$.status").value("pong"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user