A fully multiplatform, Ktor-kased NATS client in pure Kotlin
NATS.kt is a high-performance NATS client built specifically for Kotlin Multiplatform. Powered by Ktor's networking stack, it brings NATS messaging to every platform Kotlin supports - including servers, mobile apps, browsers and native applications.
- 🌐 Universal Platform Support: Deploy your NATS-powered applications anywhere Kotlin runs
- 🏗️ Transport Flexibility: TCP and WebSocket transports supported
- 🤝 Coroutines: Coroutine-based API for idiomatic reactive programming
- 🔧 Developer-First: Clean, idiomatic Kotlin API with DSL configuration
- ⚡ Built on Ktor: Leverage Ktor's stability for networking capabilities and performance
| Platform | Status | 
|---|---|
| JVM | ✅ Full Support | 
| Android | ✅ Full Support | 
| iOS (ARM64) | ✅ Full Support | 
| iOS Simulator (ARM64) | ✅ Full Support | 
| macOS (ARM64) | ✅ Full Support | 
| Linux (x64) | ✅ Full Support | 
| Linux (ARM64) | ✅ Full Support | 
| JavaScript (Browser) | ✅ Full Support | 
| JavaScript (Node.js) | ✅ Full Support | 
| WebAssembly | ✅ Full Support | 
Gradle:
commonMain.dependencies {
	implementation("io.github.n-hass:natskt-core:0.2.0")
}import io.natskt.NatsClient
// Simple connection
val client = NatsClient("nats://localhost:4222")
client.connect()
// Advanced configuration
val client = NatsClient {
    server = "nats://localhost:4222"
    transport = TcpTransport
}
val client = NatsClient {
    server = "ws://localhost:4222"
    transport = WebSocketTransport.Factory(CIO)
}
// Subscribe to messages
val subscription = client.subscribe("orders.new")
subscription.messages.collect { message ->
    println("Received: ${message.payload}")
}NATS.kt is under active development.
| Feature | Status | Notes | 
|---|---|---|
| Core Protocol | ||
| Multiplatform TCP/WebSocket transport | ✅ | |
| Authentication | ✅ | * See security notice at end! | 
| Publish/Subscribe | ✅ | |
| Request/Reply | ✅ | |
| Jetstream | ||
| Basic API | 🚧 | |
| Pull consumer | 🚧 | Core fetch/ack implementation | 
| Push consumer | ❌ | |
| Key-Value Store | ❌ | |
| Object Store | ❌ | |
| JetStream Management | ||
| Streams | 🚧 | |
| Consumers | ❌ | 
Legend: ✅ Complete | 🚧 In Progress | ❌ Planned
My priority right now is to reach a good level of stability and correctness with all JetStream consumer features, then to go back and address any performance optimisations that can be made.
Check out our examples directory for comprehensive usage examples:
- Basic Subscribe - Simple message subscription
More coming soon!
Please do not rely on the NKEY/Creds authentication features included in this client in a production environment. Although functionally correct, some cryptographic operations have not been formally verified and may have vulnerabilities.
The NKEY implementation uses an Ed25519 algorithm implementation from an un-attested library. This is used to sign authentication requests by the server on connect.
I plan to move the NKEY implementation to use cryptography-kotlin, a multiplatform binding to various other platform-native attested libraries, like JCA, OpenSSL and WebCrypto. This is waiting on the features being developed in that library upstream.
The rest of the secure operations, including secure-random and TLS for TCP and WebSocket transports, use implementations which delegate to platform-native libraries and should not pose a notable security risk.
NATS.kt is released under the Apache 2.0 License.
- Dimensional-Fun NATS.kt - For some foundational code and inspiration
- Ktor - The networking foundation
Ready to build the next generation of distributed Multiplatform applications? Star ⭐ this repo and join our community!