KubeMQ
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:

PropertyTypeDescription
messageStringHuman-readable error description
codeErrorCodeMachine-readable error code (enum)
categoryErrorCategoryError category (enum)
isRetryableBooleanWhether 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

  1. Reuse client instances -- one client per pattern handles all channels
  2. Use batch APIs for high-throughput queue workloads (sendQueueMessagesBatch)
  3. Use publishEventStream for high-throughput event publishing
  4. Use use { } blocks -- all clients implement Closeable
  5. Cancel Flow collection with coroutine cancellation to stop subscriptions
  6. Avoid blocking in collect -- use launch for heavy processing

Resources

See Also

Was this page helpful?

On this page