Repository navigation
Upgrade NATS transport to NATS.NET 3.3.0 push consumers - #1818
Open
yang-xiaodong wants to merge 1 commit into
Open
yang-xiaodong wants to merge 1 commit into
yang-xiaodong wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Concurrent consumer creation can still fail when NATS returns conflict code 10105.
Review effort: Balanced
Findings: 1
What changed in this PR
Migrates the NATS transport to NATS.NET 3.3.0 push consumers while preserving durable subscriptions and rolling-upgrade compatibility.
Changes:
- Migrates publishing, consumption, pooling, and acknowledgments to asynchronous NATS.NET APIs.
- Preserves durable consumers and stream configuration.
- Adds integration tests and migration documentation.
| File | Description |
|---|---|
CAP.sln |
Registers the NATS test project. |
src/DotNetCore.CAP.NATS/CAP.NATSOptions.cs |
Updates native configuration APIs. |
src/DotNetCore.CAP.NATS/DotNetCore.CAP.NATS.csproj |
Upgrades the NATS dependency. |
src/DotNetCore.CAP.NATS/IConnectionPool.cs |
Defines asynchronous pool operations. |
src/DotNetCore.CAP.NATS/IConnectionPool.Default.cs |
Implements asynchronous pooling. |
src/DotNetCore.CAP.NATS/ITransport.NATS.cs |
Migrates publishing to NATS.NET. |
src/DotNetCore.CAP.NATS/NATSConsumerClient.cs |
Implements durable push consumption. |
src/DotNetCore.CAP.NATS/NATSConsumerClientFactory.cs |
Connects and disposes consumers asynchronously. |
test/DotNetCore.CAP.NATS.Test/DotNetCore.CAP.NATS.Test.csproj |
Configures the integration-test project. |
test/DotNetCore.CAP.NATS.Test/DockerRestartTests.cs |
Tests restart recovery. |
test/DotNetCore.CAP.NATS.Test/NatsIntegrationTests.cs |
Covers transport and compatibility behavior. |
test/DotNetCore.CAP.NATS.Test/NatsTestScope.cs |
Provides NATS test infrastructure. |
test/DotNetCore.CAP.NATS.Test/README.md |
Documents integration-test execution. |
docs/content/user-guide/en/transport/nats.md |
Updates English migration guidance. |
docs/content/user-guide/zh/transport/nats.md |
Updates Chinese migration guidance. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+199
to
+201
| catch (NatsJSApiException conflict) when (conflict.Error.ErrCode is 10013 or 10148) | ||
| { | ||
| OnLogCallback!(new LogMessageEventArgs() | ||
| { | ||
| LogType = MqLogType.ConnectError, | ||
| Reason = $"An error was encountered when attempting to subscribe to subject: {subject}.{Environment.NewLine}" + | ||
| $"{e.Message}" | ||
| }); | ||
| consumer = await js.GetPushConsumerAsync(stream, opts.DurableName, _stopping.Token).ConfigureAwait(false); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description:
The NATS transport currently depends on NATS.Client 1.1.8. Migrate it to NATS.NET 3.3.0, whose public push-consumer API allows CAP to retain durable queue subscriptions: instances in the same group compete for messages, while different groups receive their own copy.
Existing consumers retain their durable names, delivery subjects and acknowledgment progress, allowing old and new clients to coexist during rolling upgrades and rollbacks.
Issue(s) addressed:
Changes:
Affected components:
How to test:
dotnet test test/DotNetCore.CAP.NATS.Test/DotNetCore.CAP.NATS.Test.csproj.dotnet test test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj.dotnet pack src/DotNetCore.CAP.NATS/DotNetCore.CAP.NATS.csproj --configuration Release.Local validation with NATS Server 2.10.22:
Additional notes:
This changes public native configuration types and the custom connection-pool interface. Options now uses NatsOpts; StreamOptions uses Action; ConsumerOptions returns NatsJSPushConsumerOpts; CustomHeadersBuilder receives INatsJSMsg<byte[]> directly. Custom pools use asynchronous rent/return methods and INatsConnection. Simple UseNATS(string) configuration remains unchanged.
ConsumerOptions configures new consumers; existing server-side configuration is validated and reused. CAP continues to acknowledge after receive storage/enqueue, with business-method retries managed by CAP. Migration details and the NATS.NET 3.3.0 limitation around SubOpts on reused consumers are documented.
The existing Microsoft.Build.Tasks.Git 10.0.203 dependency produces an NU1902 warning during validation; it is outside this change.
Checklist: