fixing Gradle

This commit is contained in:
stefan
2025-08-01 11:31:29 +02:00
parent 4ea084bd1d
commit a9a43a7acf
44 changed files with 244 additions and 5552 deletions
@@ -1,53 +1,56 @@
package at.mocode.core.domain.event
import at.mocode.core.domain.serialization.KotlinInstantSerializer
import at.mocode.core.domain.serialization.UuidSerializer
import com.benasher44.uuid.Uuid
import com.benasher44.uuid.uuid4
import java.util.UUID
import kotlin.time.Clock
import kotlin.time.Instant
import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable
/**
* Base interface for all domain events in the system.
* A domain event represents something significant that has happened in a specific domain.
* Basis-Interface für alle Domänen-Events im System.
* Ein Domänen-Event repräsentiert etwas fachlich Bedeutsames, das passiert ist.
*/
interface DomainEvent {
val eventId: Uuid
val aggregateId: Uuid
val eventType: java.time.Instant
val timestamp: Instant
val version: Int
// OPTIMIZED: Added correlation and causation IDs for distributed tracing.
/**
* Tracks a chain of events initiated by a single user action across multiple services.
*/
val eventType: String
val timestamp: kotlin.time.Instant
val version: Long // KORRIGIERT: Einheitlich auf Long
val correlationId: Uuid?
/**
* Tracks the direct cause of this event (the ID of the preceding event or command).
*/
val causationId: Uuid?
}
/**
* Abstract base class for domain events to reduce boilerplate code.
* Abstrakte Basisklasse für Domänen-Events, um Boilerplate-Code zu reduzieren.
*/
@Serializable
abstract class BaseDomainEvent(
@Serializable(with = UuidSerializer::class)
override val aggregateId: Uuid,
override val eventType: java.time.Instant,
override val version: Int,
override val eventType: String,
override val version: Long, // KORRIGIERT: Einheitlich auf Long
@Serializable(with = UuidSerializer::class)
override val eventId: Uuid = uuid4(),
override val timestamp: Instant = Clock.System.now(),
@Serializable(with = KotlinInstantSerializer::class)
override val timestamp: kotlin.time.Instant = kotlin.time.Clock.System.now(), // KORRIGIERT: Einheitlich auf kotlinx.datetime.Instant
@Serializable(with = UuidSerializer::class)
override val correlationId: Uuid? = null,
@Serializable(with = UuidSerializer::class)
override val causationId: Uuid? = null
) : DomainEvent
// ... (DomainEventPublisher and DomainEventHandler interfaces remain the same)
/**
* Interface für einen Publisher, der Domänen-Events veröffentlichen kann.
*/
interface DomainEventPublisher {
suspend fun publish(event: DomainEvent)
suspend fun publishAll(events: List<DomainEvent>)
}
/**
* Interface für einen Handler, der auf bestimmte Domänen-Events reagieren kann.
*/
interface DomainEventHandler<T : DomainEvent> {
suspend fun handle(event: T)
fun canHandle(eventType: String): Boolean
+2 -1
View File
@@ -26,7 +26,8 @@ dependencies {
api(libs.hikari.cp)
// Service Discovery
api(libs.consul.client)
// api(libs.consul.client) wird getauscht mir spring-cloud-starter-consul-discovery
api(libs.spring.cloud.starter.consul.discovery)
// Logging
api(libs.kotlin.logging.jvm)
@@ -1,103 +0,0 @@
package at.mocode.core.utils.discovery
import at.mocode.core.utils.config.AppConfig
import com.orbitz.consul.Consul
import com.orbitz.consul.model.agent.ImmutableRegistration
import com.orbitz.consul.model.agent.Registration
import org.slf4j.LoggerFactory
import java.util.*
class ServiceRegistration internal constructor(
private val consul: Consul,
private val registration: ImmutableRegistration
) {
private companion object {
private val logger = LoggerFactory.getLogger(ServiceRegistration::class.java)
}
private var isRegistered = false
fun register() {
if (isRegistered) return
try {
consul.agentClient().register(registration)
isRegistered = true
logger.info(
"Service '{}' with ID '{}' successfully registered with Consul.",
registration.name(),
registration.id()
)
} catch (e: Exception) {
logger.error("Failed to register service '{}' with Consul.", registration.name(), e)
throw IllegalStateException("Could not register service with Consul", e)
}
}
fun deregister() {
if (!isRegistered) return
try {
consul.agentClient().deregister(registration.id())
isRegistered = false
logger.info(
"Service '{}' with ID '{}' successfully deregistered from Consul.",
registration.name(),
registration.id()
)
} catch (e: Exception) {
logger.error("Failed to deregister service '{}' from Consul.", registration.id(), e)
}
}
}
class ServiceRegistrar(private val appConfig: AppConfig) {
private companion object {
private val logger = LoggerFactory.getLogger(ServiceRegistrar::class.java)
}
private val consul: Consul by lazy {
val consulConfig = appConfig.serviceDiscovery
logger.info("Connecting to Consul at {}:{}", consulConfig.consulHost, consulConfig.consulPort)
Consul.builder()
.withUrl("http://${consulConfig.consulHost}:${consulConfig.consulPort}")
.build()
}
fun registerCurrentService(): ServiceRegistration {
val serviceName = appConfig.appInfo.name
val servicePort = appConfig.server.port
val serviceId = "$serviceName-${UUID.randomUUID()}"
val hostAddress = appConfig.server.advertisedHost
val healthCheck = Registration.RegCheck.http(
"http://$hostAddress:$servicePort/health",
10L,
5L
)
// ========= FINALE KORREKTUR =========
// Wir erstellen die Liste und die Map VORHER mit expliziten Typen,
// um dem Compiler bei der Typinferenz zu helfen.
val serviceTags: List<String> = listOf("env:${appConfig.environment.name.lowercase()}")
val serviceMeta: Map<String, String> = mapOf("version" to appConfig.appInfo.version)
val registration = ImmutableRegistration.builder()
.id(serviceId)
.name(serviceName)
.address(hostAddress)
.port(servicePort)
.check(healthCheck)
.tags(serviceTags) // Verwenden der explizit typisierten Variablen
.meta(serviceMeta) // Verwenden der explizit typisierten Variablen
.build()
val serviceRegistration = ServiceRegistration(consul, registration)
serviceRegistration.register()
Runtime.getRuntime().addShutdownHook(Thread {
logger.info("Shutdown hook triggered: Deregistering service '{}'...", serviceId)
serviceRegistration.deregister()
})
return serviceRegistration
}
}