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

Add JetStream NATS Client Extensions #598

Merged
merged 14 commits into from
Sep 18, 2024
Merged

Add JetStream NATS Client Extensions #598

merged 14 commits into from
Sep 18, 2024

Conversation

mtmk
Copy link
Collaborator

@mtmk mtmk commented Aug 6, 2024

This PR introduces an interface-based Core API dependency for the JetStream API and an extension to INatsClient interface:

await using var client = new NatsClient();
var js = client.CreateJetStreamContext(); // extension method usage

As a result of this change, several internal APIs will need to be made public. This will enable application developers to extend some of the lower-level features. This aligns with our overall mission to establish INatsClient as the default API level, providing the opportunity to introduce lower-level functions from our library through INatsConnection.

  • INatsConnection: Opened functions mostly useful for creating custom subscribers which are used in JetStream consumer implementation.

  • NatsSubBase: Reviewed and documented subscription base class to be inherited for custom subscriptions.

  • INatsSubscriptionManager: Exposed the subscription manager as an interface, only having the single function opened used in current implementations. This could be opened up more as we see opportunities or demand.

  • JetStream NatsClientExtensions: Convenience extension to create JetStream context.

@mtmk mtmk changed the title Nats client js changes WIP Nats client js changes Aug 6, 2024
@mtmk mtmk changed the title WIP Nats client js changes Add JetStream NATS Client Extensions Aug 6, 2024
@mtmk mtmk marked this pull request as ready for review August 6, 2024 18:49
Copy link
Collaborator

@to11mtm to11mtm left a comment

Choose a reason for hiding this comment

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

very minor stuff (If it wasn't handled before I finally submitted >_<)

/// <param name="pending">The number of pending messages at the time the drop occurred.</param>
/// <param name="msg">The dropped message represented by <see cref="NatsMsg{T}"/>.</param>
/// <typeparam name="T">Specifies the type of data in the dropped message.</typeparam>
void OnMessageDropped<T>(NatsSubBase natsSub, int pending, NatsMsg<T> msg);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I had one 'thought' here...

maybe as <remarks> XmlDoc... explaining to people why this -isn't- a valuetask... e.x.

<remarks>This method is expected to complete quickly to avoid further delays in processing; if complex work is required, it is recommended to offload to a channel or other out-of-band processor</remarks>

but... as usual may be overthinking >_<

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it is an important detail to mention

@@ -35,7 +35,7 @@ protected override void TryComplete()
}
}

internal class InboxSubBuilder : ISubscriptionManager
internal class InboxSubBuilder : INatsSubscriptionManager
Copy link
Collaborator

Choose a reason for hiding this comment

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

Almost left a comment here but see that ISubscriptionManager was internal so it shouldn't break things for sane consumers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

true. I guess it will break binary compatibility but we're coming out with a few breaking changes here applications will need to rebuild anyway.

Comment on lines 3 to 6
public interface INatsSubscriptionManager
{
public ValueTask RemoveAsync(NatsSubBase sub);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is public now should we XMLDoc it?

(If 'public but really internal' perhaps an XMLDoc stating it is an internal API subject to change?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

mtmk added 3 commits August 23, 2024 11:40
# Conflicts:
#	sandbox/Example.Client/Example.Client.csproj
#	sandbox/Example.Client/Program.cs
#	tests/NATS.Client.Simplified.Tests/ClientTest.cs
@mtmk mtmk added this to the 2.4.0 milestone Aug 24, 2024
@darkwatchuk
Copy link
Contributor

Hi,

As part of this PR would it please be possible to expose the INatsConnection Connection property from NatsJSContext, either by making it Public, or a function like INatsConnection GetConnection() ?

In the same way, could NatsKVStore and NatsObjStore expose the underlying NatsJSContext?

This would be really handy as it would allow developers to easily add their own extension methods if need be.

Would be great if this was possible! Many thanks!

@mtmk
Copy link
Collaborator Author

mtmk commented Sep 9, 2024

As part of this PR would it please be possible to expose the INatsConnection Connection property from NatsJSContext, either by making it Public, or a function like INatsConnection GetConnection() ?

Good idea! done as a property.

In the same way, could NatsKVStore and NatsObjStore expose the underlying NatsJSContext?

We have a few issues as todo items for those, added a note to do that:

thanks @darkwatchuk 💯

@darkwatchuk
Copy link
Contributor

That's great - thank you

@mtmk mtmk modified the milestones: 2.4.0, 2.5.0 Sep 9, 2024
Copy link
Collaborator

@rickdotnet rickdotnet left a comment

Choose a reason for hiding this comment

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

LGTM! Nice work.

@mtmk
Copy link
Collaborator Author

mtmk commented Sep 14, 2024

LGTM! Nice work.

thanks @rickdotnet 💯

I will merge just after 2.4 stable release which I'm planning to do first thing next week

@mtmk mtmk merged commit 442db86 into main Sep 18, 2024
13 checks passed
@mtmk mtmk deleted the nats-client-js-changes branch September 18, 2024 07:04
mtmk added a commit that referenced this pull request Oct 1, 2024
* Added Domain support for stream mirroring and sourcing and KV full support for the same. (#631)
* Adds type-forwarders NET 5.0+ (#641)
* Run core tests on Windows and test run stability (#464)
* Add JetStream NATS Client Extensions (#598)
@mtmk mtmk mentioned this pull request Oct 1, 2024
mtmk added a commit that referenced this pull request Oct 1, 2024
* Added Domain support for stream mirroring and sourcing and KV full support for the same. (#631)
* Adds type-forwarders NET 5.0+ (#641)
* Run core tests on Windows and test run stability (#464)
* Add JetStream NATS Client Extensions (#598)
mtmk added a commit that referenced this pull request Oct 9, 2024
* Add placement configuration to key-value and object store (#650)
* Bump System.Text.Json from 8.0.4 to 8.0.5 in /src/NATS.Client.Core (#649)
* Add other client extensions (#637)
* Add Domain support for stream mirroring and sourcing and KV full support for the same. (#631)
* Add type-forwarders NET 5.0+ (#641)
* Add JetStream NATS Client Extensions (#598)
@mtmk mtmk mentioned this pull request Oct 9, 2024
mtmk added a commit that referenced this pull request Oct 9, 2024
* Add placement configuration to key-value and object store (#650)
* Bump System.Text.Json from 8.0.4 to 8.0.5 in /src/NATS.Client.Core (#649)
* Add other client extensions (#637)
* Add Domain support for stream mirroring and sourcing and KV full support for the same. (#631)
* Add type-forwarders NET 5.0+ (#641)
* Add JetStream NATS Client Extensions (#598)
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.

4 participants