Skip to content

Add JetStream NATS Client Extensions#598

Merged
mtmk merged 14 commits into
mainfrom
nats-client-js-changes
Sep 18, 2024
Merged

Add JetStream NATS Client Extensions#598
mtmk merged 14 commits into
mainfrom
nats-client-js-changes

Conversation

@mtmk

@mtmk mtmk commented Aug 6, 2024

Copy link
Copy Markdown
Member

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

@to11mtm to11mtm left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Member 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

}

internal class InboxSubBuilder : ISubscriptionManager
internal class InboxSubBuilder : INatsSubscriptionManager

Copy link
Copy Markdown
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
Copy Markdown
Member 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
Copy Markdown
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
Copy Markdown
Member 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
Copy Markdown
Collaborator

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

mtmk commented Sep 9, 2024

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Collaborator

That's great - thank you

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

@rickdotnet rickdotnet left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Nice work.

@mtmk

mtmk commented Sep 14, 2024

Copy link
Copy Markdown
Member Author

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
@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