-
-
Notifications
You must be signed in to change notification settings - Fork 278
Add NATS.io as a Transport option for Wolverine #1999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NATS.io as a Transport option for Wolverine #1999
Conversation
…e nats instances running
…reply and requeue functionality
…opReceivingAsync SemaphoreSlim(0, 1) starts with 0 permits, causing the first WaitAsync() to block forever. Changed to SemaphoreSlim(1, 1) to start with 1 permit.
…for nats core messaging (empty message)
| } | ||
|
|
||
| private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(0, 1); | ||
| private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This slipped in here for the issue i raised #1998 can make this a separate PR if thats agreed to use mutex vs signal pattern. But for now I wanted to ensure all tests pass
|
@thedonmon Honestly, I'm pulling this in -- after a rebase -- then I'll do a much better review with it in main. Doesn't hurt anything if it isn't released. But first, thank you for taking this on and pushing it through! |
Awesome! Yes no problem happy to help with review of anything and more testing as needed! I tried to follow other transports best as possible but there were some nuances with NATS I had to work around. |
Summary
For the love of the game, I've been using NATS for all of my messaging infrastructure and really fallen in love with it. I thought it would be a great fit for Wolverine since it has a lot of powerful features combining the likes of Kafka and Rabbit with one protocol. There are other features that could be cool for persistence like the ObjectStore (S3 like) and KeyValue Store (Redis like) but for now focusing on the core messaging infrastructure to incorporate into Wolverine.
Happy to add more docs, or tests and open to any feedback or questions!
Adds NATS as a first-class transport for Wolverine, supporting both Core NATS (fire-and-forget pub/sub) and JetStream (persistent, durable messaging with acknowledgments).
Closes #1038
Features
Core NATS Support
JetStream Support
AckTerminateWorkQueuePolicyConfiguration Examples
Architecture: Why Core NATS and JetStream Are Separate
NATS has two distinct messaging models with fundamentally different guarantees:
NakAsync()AckTerminateAsync()The transport implementation reflects this split:
CoreNatsSubscriber/CoreNatsPublisher- For simple pub/subJetStreamSubscriber/JetStreamPublisher- For durable messagingCan they be used together? Yes! In the same application:
The response endpoint (
wolverine.response.*) always uses Core NATS for request-reply, even when the main endpoints use JetStream.Test Results
All 85 tests pass:
Native Scheduled Message Delivery
The transport supports native scheduled message delivery when using JetStream with NATS Server 2.12+.
Requirements
EnableScheduledDelivery()How It Works
When conditions are met,
SupportsNativeScheduledSendreturnstrueand scheduled messages use NATS headers:Nats-Schedule: @at <RFC3339 timestamp>Nats-Schedule-Target: <subject>The transport automatically detects server version at startup and logs:
Configuration
Fallback Behavior
When native scheduled send is not available (server < 2.12 or stream not configured), Wolverine automatically falls back to its database-backed scheduled message persistence. This ensures scheduled messages work reliably across all NATS versions.
Known Limitations
Requeue Behavior
NakAsync()with optional delayFiles Added/Modified
New Files
src/Transports/NATS/Wolverine.Nats/- Main transport libraryNatsTransportExtensions.cs- Extension methods for configurationInternal/NatsTransport.cs- Transport implementationInternal/NatsEndpoint.cs- Endpoint configurationInternal/NatsSender.cs- Message sendingInternal/NatsListener.cs- Message receivingInternal/CoreNatsSubscriber.cs/JetStreamSubscriber.cs- Subscription handlingInternal/CoreNatsPublisher.cs/JetStreamPublisher.cs- PublishingInternal/NatsEnvelopeMapper.cs- Header mappingsrc/Transports/NATS/Wolverine.Nats.Tests/- Test projectModified Files
wolverine.sln- Added NATS projectsTesting
Dependencies
NATS.Net(v2.7.0+) - Official NATS .NET clientBreaking Changes
None - this is a new transport addition.
Checklist