Skip to content

dimensional-fun/nats.kt

Repository files navigation

NATS - Kotlin Client

An idiomatic & multi-platform Kotlin client for the NATS messaging system.

Warning

nats.kt is currently in active development!

Installation

Requires Kotlin 1.9 and Java 19 if you're using the JVM artifact.

  • Latest Version: None

🐘 Gradle

repositories {
    maven("https://maven.dimensional.fun/releases") // or snapshots
}

dependencies {
    implementation("fun.dimensional:knats-core:{VERSION}")
    implementation("fun.dimensional:knats-jetstream:{VERSION}")
    implementation("fun.dimensional:knats-micro:{VERSION}")
}

Example

Creating a Client

// create and connect a new NATS client.
val client = Client("nats://127.0.0.1:4222") {
    // use the TCP transport, you could also use the WebSocket transport.
    transport = TcpTransport
}

Subscriptions

// create a subscription listening on all subjects.
val all = client.subscribe(">")

all.on<SubscriptionUnsubscribedEvent> {
    println("Subscription was ${if (auto) "auto-" else ""}unsubscribed.")
}

all.on<SubscriptionDeliveryEvent> {
    println("Received message $id on \"${delivery.subject}\"!")
}

more coming soon


Unless specified otherwise, all files are licensed under the Apache Version 2.0 license.

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages