Client SDKsKotlinReference
Types & Errors
Sealed exception hierarchy, types, and performance guidance -- KubeMQ Kotlin SDK reference.
Kotlin messages are built with DSL builders (eventMessage { }, queueMessage { }, commandMessage { }, etc.). Responses map to EventSendResult, QueueReceiveResponse, CommandResponse, and QueryResponse.
Exception hierarchy
The Kotlin SDK uses a sealed class hierarchy for type-safe error handling with when expressions:
KubeMQException (sealed)
├── Connection (retryable)
├── Timeout (retryable)
├── Authentication (non-retryable)
├── Authorization (non-retryable)
├── Validation (non-retryable)
├── Throttling (retryable)
├── Transport (varies)
├── Server (varies)
├── ClientClosed (non-retryable)
└── StreamBroken (retryable)Common properties
All KubeMQException subclasses share:
| Property | Type | Description |
|---|---|---|
message | String | Human-readable error description |
code | ErrorCode | Machine-readable error code (enum) |
category | ErrorCategory | Error category (enum) |
isRetryable | Boolean | Whether the operation can be retried |
Type-safe error handling
try {
client.publishEvent(message)
} catch (e: KubeMQException) {
when (e) {
is KubeMQException.Connection -> println("Connection: ${e.message}")
is KubeMQException.Timeout -> println("Timeout: ${e.message}, duration=${e.duration}")
is KubeMQException.Authentication -> println("Auth: ${e.message}")
is KubeMQException.Authorization -> println("Authz: ${e.message}, channel=${e.channel}")
is KubeMQException.Validation -> println("Validation: ${e.message}, op=${e.operation}")
is KubeMQException.Throttling -> println("Throttled: ${e.message}")
is KubeMQException.Transport -> println("Transport: ${e.message}")
is KubeMQException.Server -> println("Server: ${e.message}, status=${e.statusCode}")
is KubeMQException.ClientClosed -> println("Closed: ${e.message}")
is KubeMQException.StreamBroken -> println("Stream: ${e.message}")
}
}Connection state
sealed interface ConnectionState {
data object Idle : ConnectionState
data object Connecting : ConnectionState
data object Ready : ConnectionState
data class Reconnecting(val attempt: Int) : ConnectionState
data object Closed : ConnectionState
}Performance tips
- Reuse client instances -- one client per pattern handles all channels
- Use batch APIs for high-throughput queue workloads (
sendQueueMessagesBatch) - Use
publishEventStreamfor high-throughput event publishing - Use
use { }blocks -- all clients implementCloseable - Cancel Flow collection with coroutine cancellation to stop subscriptions
- Avoid blocking in
collect-- uselaunchfor heavy processing
Resources
See Also
Was this page helpful?