Client SDKsKotlinReference
Events
API reference for KubeMQ real-time pub/sub events in the Kotlin SDK PubSubClient, with the eventMessage DSL.
Use PubSubClient for fire-and-forget events. Messages are built with the eventMessage { } DSL; subscriptions return a Flow of received events.
publishEvent
suspend fun publishEvent(message: EventMessage)Publishes an event to the channel embedded in EventMessage.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
message | EventMessage | Yes | Built via eventMessage { } DSL |
Throws: KubeMQException -- transport, validation, or auth failures.
publishEventStream
fun publishEventStream(events: Flow<EventMessage>): Flow<EventSendResult>Streams events for high-throughput publishing. Accepts a Flow of messages and returns a Flow of results.
subscribeToEvents
fun subscribeToEvents(config: EventsSubscriptionConfig.() -> Unit): Flow<EventMessageReceived>Returns a cold Flow that subscribes to a channel when collected. Supports optional consumer group for competing consumers.
Configuration DSL:
| Property | Type | Required | Description |
|---|---|---|---|
channel | String | Yes | Channel to subscribe to (supports > wildcard) |
group | String | No | Consumer group for load balancing |
eventMessage DSL
eventMessage {
channel = "events.orders"
body = "created".toByteArray()
metadata = "order-service"
tags = mapOf("priority" to "high")
}| Property | Type | Description |
|---|---|---|
channel | String | Target channel |
body | ByteArray | Binary payload |
metadata | String | UTF-8 metadata |
tags | Map<String, String> | Key/value tags |
Quick Usage
KubeMQClient.pubSub {
address = "localhost:50000"
clientId = "events-demo"
}.use { pub ->
pub.publishEvent(eventMessage {
channel = "events.orders"
body = "created".toByteArray()
})
}See Also
Was this page helpful?