Skip to content

Conversation

@tbshrst
Copy link

@tbshrst tbshrst commented Nov 7, 2025

Hello folks,

I'm proposing a NATS integration for kumo to publish messages to NATS servers with JetStream enabled. I think this is a good use case, since NATS is pretty popular, especially in the cloud-native environment. It supports publishing messages and authenticates itself via password or token. Unlike mod-kafka, a builder pattern is used in Rust, so the Lua input must be translated. The proposal employs the async-nats crate.

The interface looks like this:

local nats = kumo.nats.connect {
	servers = {"127.0.0.1:4222"},
	name = "nats-client",
	auth = {
		username = "user",
		password = "somepassword",
	}
}

nats:publish {
	subject = "my.subject",
	payload = "hello from kumomta!",
	headers = {
		["Nats-Msg-Id"] = "unique-key",
	},
	await_ack = true, -- optional
}
nats:close()

I haven't written any documentation yet, as I wanted to wait for your response first.

Copy link
Collaborator

@wez wez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!
I have to confess that I hadn't encountered NATS until now.
I think the code looks reasonable!

We'll need to have some tests in here to verify that things are behaving reasonably.
I'd suggest using https://docs.rs/testcontainers-modules/latest/testcontainers_modules/nats/index.html to spawn a NATS container. Look at crates/integration-tests/src/rabbit.rs to see how we do the rabbitmq tests using testcontainers.

The rabbit tests load the "default" crates/integration-tests/source.lua policy file, which is now getting a bit overloaded with various env vars for different tests, so I'd suggest making a new dedicated test policy file for nats.

Please take a look at these two recent PRs for more general discussion on integration tests to see how to accommodate an alternate policy file for testing:

@tbshrst
Copy link
Author

tbshrst commented Nov 18, 2025

Thanks for your suggestions! I have implemented Keysource for credentials, as well as integration tests that test message publishing.

@tbshrst tbshrst force-pushed the mod-nats branch 4 times, most recently from 1ba361f to 3a81380 Compare November 19, 2025 08:10
@tbshrst tbshrst requested a review from wez December 1, 2025 17:21
tbshrst and others added 7 commits January 8, 2026 18:15
Publish messages using the jetstream client.
Supports password and token authentication.

usage:

```
local nats = kumo.nats.connect {
	servers = {"127.0.0.1:4222"},
}
nats:publish {
	subject = "my.subject",
	payload = "my payload",
	headers = {
		["Nats-Msg-Id"] = "unique-message-id",
	},
	await_ack = true,
}
nats:close()
```

Apply suggestions from code review

Co-authored-by: Wez Furlong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants