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.
JVM framework adapters · Java 17 · version 3.3.2
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.
CoAkka target
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
Giữ HTTP khi endpoint có owner độc lập, URL/discovery, status, headers, auth propagation và governance riêng.
Framework edge
Spring/Quarkus vẫn sở hữu public ingress, transactions, validation, framework security và public response.
// 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")runtime:3.3.2; không tạo Core thứ hai.@Component
class CustomerCapabilityHandlers(
private val store: InMemoryCustomerStore,
) {
@CoAkkaHandler("samples.customer.create")
fun create(command: CustomerDraft): MutationResponse {
return store.create(command)
}
}@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.
@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,
)
}
}@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.
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.
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}
rootProject.name = "coakka-portal-framework-checks"
include("spring-app", "quarkus-app")
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)
}
}
}
kotlin.compiler.execution.strategy=in-process
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) }
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)
}
server.port=18082
coakka.runtime.system-name=portal-spring
coakka.runtime.node-id=portal-spring-1
coakka.runtime.source-target=portal.spring.http
gradle :spring-app:bootJar
java -jar spring-app/build/libs/spring-app.jarcurl http://127.0.0.1:18082/verifyplugins {
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) }
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.http.port=18083
coakka.runtime.system-name=portal-quarkus
coakka.runtime.node-id=portal-quarkus-1
coakka.runtime.source-target=portal.quarkus.http
gradle :quarkus-app:quarkusBuild
java -jar quarkus-app/build/quarkus-app/quarkus-run.jarcurl http://127.0.0.1:18083/verifyReply 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.
coakka.runtime.monitor-enabled=truestartupConfig() thay vì dựng effective state từ properties.