Skip to content
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

Introducing NATS stream provider #9379

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

galvesribeiro
Copy link
Member

@galvesribeiro galvesribeiro commented Mar 11, 2025

This PR introduces a new stream provider for NATS.io.

The provider implementation follow the same approach as others which are based on queues. In this case, we use NATS JetStream stream as the backend "queue".

Each provider registration uses one NATS JetStream Stream. That stream is partitioned based on NatsOptions.PartitionCount using the Deterministic subject token partition making each pooling agent responsible for each partition.

Unlike all other providers, the state of the consumer is 100% managed by NATS Server. Consumers are named per partition, so if the partition owner changes, the next owner will continue to consume automatically. No need for external checkpoint storage. The provider acknowledge messages delivered upon delivery.

For now, it is implemented as a non-rewindable stream. We can later on enhance it to add rewind support, just need a bit more time and can be done on a separated PR.

Another area to investigate, is to use NATS KV for storage. In particular for PubSubStorage. The KV have interesting use cases like for example, external systems can be notified about state changes. That would allow people to self-contain the streaming without any other dependency, but this will go in another PR later.

Microsoft Reviewers: Open in CodeFlow

@galvesribeiro galvesribeiro force-pushed the nats-stream-provider branch 3 times, most recently from 4a0b570 to 259d4f8 Compare March 12, 2025 01:40
@ReubenBond ReubenBond requested a review from Copilot March 12, 2025 02:43
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces a new NATS JetStream stream provider for Orleans. Key changes include new implementations for the stream consumer, queue adapter receiver, and related adapter factory as well as test infrastructure and CI configuration updates to validate the NATS provider.

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/Extensions/NATS.Tests/NatsAdapterTests.cs New tests for the NATS adapter functionality
src/Orleans.Streaming.NATS/Providers/NatsStreamConsumer.cs Implementation of the NATS stream consumer using JetStream APIs
src/Orleans.Streaming.NATS/Providers/StreamIdJsonConverter.cs JSON converter for StreamId serialization
src/Orleans.Streaming.NATS/Providers/NatsQueueAdapterReceiver.cs New queue adapter receiver implementation for NATS streams
src/Orleans.Streaming.NATS/NatsOptions.cs Options class for configuring the NATS provider
src/Orleans.Streaming.NATS/Providers/NatsBatchContainer.cs New batch container for NATS-based streams
src/Orleans.Streaming.NATS/Providers/NatsConnectionManager.cs Manages NATS connection and stream consumer creation
test/Extensions/NATS.Tests/NatsClientStreamTests.cs Additional tests for client stream scenarios using NATS
src/Orleans.Streaming.NATS/Hosting/* Extension methods and configurators to wire up NATS streams in silos and clients
.github/workflows/ci.yml Updated CI workflow to include NATS stream provider tests
src/Orleans.Streaming.NATS/Providers/NatsAdapterFactory.cs, NatsAdapter.cs, NatsStreamMessage.cs, NatsStreamConfigurator.cs New adapter factory, adapter, message, and configurator implementations for the NATS stream provider
Comments suppressed due to low confidence (1)

src/Orleans.Streaming.NATS/Providers/NatsQueueAdapterReceiver.cs:92

  • Using a literal empty array notation '[]' may be ambiguous in C#. Consider returning an explicit empty list (e.g., 'new List()') or using a well-known helper like 'Array.Empty()' for clarity.
return [];

@galvesribeiro galvesribeiro force-pushed the nats-stream-provider branch 2 times, most recently from ec49e8e to 13102d2 Compare March 27, 2025 16:19
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