JVM framework adapters · Java 17 · version 3.3.2

CoAkka Runtime với Spring Boot và Quarkus

Framework tiếp tục sở hữu HTTP, DI/CDI, validation, security và lifecycle. CoAkka Runtime chỉ nhận phần việc app-owned qua target, route, bounded admission, reply hoặc deadletter.

Chọn đúng boundary

CoAkka target

App-owned work

Dùng khi capability vẫn thuộc app/team và có thể bắt đầu local rồi chuyển peer mà call site giữ cùng target.

HTTP client

Service API thật

Giữ HTTP khi endpoint có owner độc lập, URL/discovery, status, headers, auth propagation và governance riêng.

Framework edge

Không bị thay thế

Spring/Quarkus vẫn sở hữu public ingress, transactions, validation, framework security và public response.

Hai adapter, cùng Core generation

Gradle · chọn một
// Spring Boot
implementation("io.github.phuong-tran.coakka:spring-boot-starter:3.3.2")

// Hoặc Quarkus
implementation("io.github.phuong-tran.coakka:quarkus-extension:3.3.2")
Repository
Maven Central.
Java
17 cho framework application.
Runtime dependency
Mỗi adapter phụ thuộc exact runtime:3.3.2; không tạo Core thứ hai.
Framework version
App sở hữu Spring Boot/Quarkus platform version; adapter không nhập BOM thay app.

Spring Boot: HTTP edge gọi runtime target

Kotlin · handler
@Component
class CustomerCapabilityHandlers(
    private val store: InMemoryCustomerStore,
) {
    @CoAkkaHandler("samples.customer.create")
    fun create(command: CustomerDraft): MutationResponse {
        return store.create(command)
    }
}
Kotlin · controller call site
@PostMapping("/api/customers")
@ResponseStatus(HttpStatus.CREATED)
fun create(request: CustomerDraft): MutationResponse {
    return runtimeClient.askBlocking(
        "samples.customer.create",
        request,
        MutationResponse::class.java,
        "create_customer",
        5_000,
    )
}

Controller vẫn là public HTTP boundary. Target đặt tên capability; handler có thể local hôm nay và chuyển sang peer sau mà controller không đổi thành code quản lý private URL.

Quarkus: CDI-backed handler

Kotlin · handler shape
@ApplicationScoped
@CoAkkaHandler("samples.customer.store")
class CustomerCapabilityHandler(
    private val store: InMemoryCustomerStore,
) : CoAkkaLocalHandler {
    override fun handle(
        request: ConnectorEnvelope,
        objectMapper: ObjectMapper,
    ): ConnectorEnvelope {
        val command = objectMapper.readValue(
            request.payload,
            CustomerDraft::class.java,
        )
        return CoAkkaReplies.json(
            request,
            "samples.customer.store",
            store.create(command),
            CustomerPayloads.MUTATION_RESPONSE,
            objectMapper,
        )
    }
}
Kotlin · resource call site
@POST
@Path("/api/customers")
fun create(request: CustomerDraft): MutationResponse {
    return coakka.askBlocking(
        "samples.customer.store",
        request,
        CustomerPayloads.CREATE,
        MutationResponse::class.java,
        "create_customer",
        5_000,
    )
}

CDI vẫn sở hữu bean graph và app lifecycle; CoAkka Runtime sở hữu delivery tới target và structured terminal outcome.

Chạy exact project Spring Boot và Quarkus

Tạo Gradle project hai module này. Hai app dùng Java 17 và Kotlin named argument. Mỗi framework sở hữu HTTP ở /verify; controller/resource gọi một same-process CoAkka Runtime target rồi trả JSON reply từ handler.

Gradle file dùng chung
settings.gradle.kts
pluginManagement {
    repositories {
        gradlePluginPortal()
        mavenCentral()
    }
}

rootProject.name = "coakka-portal-framework-checks"
include("spring-app", "quarkus-app")
build.gradle.kts
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "2.3.10" apply false
    kotlin("plugin.spring") version "2.3.10" apply false
    kotlin("plugin.allopen") version "2.3.10" apply false
    id("org.springframework.boot") version "3.5.16" apply false
    id("io.quarkus") version "3.35.2" apply false
}

allprojects {
    repositories { mavenCentral() }
    val outputRoot = providers.environmentVariable("COAKKA_PORTAL_BUILD_ROOT").orNull
    if (outputRoot != null) {
        layout.buildDirectory.set(file(outputRoot).resolve(path.removePrefix(":").ifEmpty { "root" }))
    }
}

subprojects {
    tasks.withType<KotlinCompile>().configureEach {
        compilerOptions {
            jvmTarget.set(JvmTarget.JVM_17)
            allWarningsAsErrors.set(true)
        }
    }
}
gradle.properties
kotlin.compiler.execution.strategy=in-process
Spring Boot module
spring-app/build.gradle.kts
plugins {
    kotlin("jvm")
    kotlin("plugin.spring")
    id("org.springframework.boot")
}

dependencies {
    implementation(platform("org.springframework.boot:spring-boot-dependencies:3.5.16"))
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("io.github.phuong-tran.coakka:spring-boot-starter:3.3.2")
}

kotlin { jvmToolchain(17) }
spring-app/src/main/kotlin/portal/spring/PortalSpringApp.kt
package portal.spring

import coakka.spring.CoAkkaHandler
import coakka.spring.CoAkkaRuntimeClient
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.stereotype.Component
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

private const val target = "portal.spring.echo"

data class EchoRequest(val message: String)

data class EchoReply(val message: String, val handledBy: String)

@Component
class EchoHandler {
    @CoAkkaHandler(target)
    fun echo(request: EchoRequest): EchoReply {
        return EchoReply(message = request.message, handledBy = "spring-handler")
    }
}

@RestController
class VerifyController(private val runtimeClient: CoAkkaRuntimeClient) {
    @GetMapping("/verify")
    fun verify(): EchoReply {
        return runtimeClient.askBlocking(
            target,
            EchoRequest(message = "hello-coakka-runtime"),
            EchoReply::class.java,
            "portal_spring_check",
            2_000,
        )
    }
}

@SpringBootApplication
class PortalSpringApp

fun main(args: Array<String>) {
    runApplication<PortalSpringApp>(*args)
}
spring-app/src/main/resources/application.properties
server.port=18082
coakka.runtime.system-name=portal-spring
coakka.runtime.node-id=portal-spring-1
coakka.runtime.source-target=portal.spring.http
Build và start
gradle :spring-app:bootJar
java -jar spring-app/build/libs/spring-app.jar
Terminal khác
curl http://127.0.0.1:18082/verify
Quarkus module
quarkus-app/build.gradle.kts
plugins {
    kotlin("jvm")
    kotlin("plugin.allopen")
    id("io.quarkus")
}

dependencies {
    implementation(platform("io.quarkus.platform:quarkus-bom:3.35.2"))
    implementation("io.quarkus:quarkus-kotlin")
    implementation("io.quarkus:quarkus-arc")
    implementation("io.quarkus:quarkus-rest-jackson")
    implementation("io.github.phuong-tran.coakka:quarkus-extension:3.3.2")
}

allOpen {
    annotation("jakarta.enterprise.context.ApplicationScoped")
    annotation("jakarta.ws.rs.Path")
}

kotlin { jvmToolchain(17) }
quarkus-app/src/main/kotlin/portal/quarkus/PortalQuarkusApp.kt
package portal.quarkus

import coakka.quarkus.CoAkkaHandler
import coakka.quarkus.CoAkkaJsonHandler
import coakka.quarkus.CoAkkaRuntimeClient
import coakka.v2.connector.protocol.ConnectorPayloadFormat
import coakka.v2.connector.protocol.ConnectorPayloadIdentity
import jakarta.enterprise.context.ApplicationScoped
import jakarta.ws.rs.GET
import jakarta.ws.rs.Path
import jakarta.ws.rs.Produces
import jakarta.ws.rs.core.MediaType

private const val target = "portal.quarkus.echo"

data class EchoRequest(val message: String = "")

data class EchoReply(val message: String = "", val handledBy: String = "")

private val requestIdentity = ConnectorPayloadIdentity(
    messageType = "portal.quarkus.echo.request.v1",
    payloadSchemaVersion = 1,
    payloadFormat = ConnectorPayloadFormat.JSON,
)
private val replyIdentity = ConnectorPayloadIdentity(
    messageType = "portal.quarkus.echo.reply.v1",
    payloadSchemaVersion = 1,
    payloadFormat = ConnectorPayloadFormat.JSON,
)

@ApplicationScoped
@CoAkkaHandler(target)
class EchoHandler : CoAkkaJsonHandler<EchoRequest, EchoReply> {
    override fun requestType(): Class<EchoRequest> = EchoRequest::class.java

    override fun responseIdentity(response: EchoReply): ConnectorPayloadIdentity {
        return replyIdentity
    }

    override fun handlePayload(payload: EchoRequest): EchoReply {
        return EchoReply(message = payload.message, handledBy = "quarkus-handler")
    }
}

@Path("/verify")
@Produces(MediaType.APPLICATION_JSON)
class VerifyResource(private val runtimeClient: CoAkkaRuntimeClient) {
    @GET
    fun verify(): EchoReply {
        return runtimeClient.askBlocking(
            target,
            EchoRequest(message = "hello-coakka-runtime"),
            requestIdentity,
            EchoReply::class.java,
            "portal_quarkus_check",
            2_000,
        )
    }
}
quarkus-app/src/main/resources/application.properties
quarkus.http.port=18083
coakka.runtime.system-name=portal-quarkus
coakka.runtime.node-id=portal-quarkus-1
coakka.runtime.source-target=portal.quarkus.http
Build và start
gradle :quarkus-app:quarkusBuild
java -jar quarkus-app/build/quarkus-app/quarkus-run.jar
Terminal khác
curl http://127.0.0.1:18083/verify

Reply mong đợi

{"message":"hello-coakka-runtime","handledBy":"spring-handler"}
{"message":"hello-coakka-runtime","handledBy":"quarkus-handler"}

Quy tắc Quarkus DTO. DTO nhỏ có default để application ObjectMapper có đường no-argument construction tường minh. Serialization failure bên trong handler không phải route miss; giữ handler cause thay vì tăng request timeout.

Cấu hình và lifecycle

application.properties · optional Monitor
coakka.runtime.monitor-enabled=true

Tra outcomes · Tra peer/failover · Tra effective state