Skip to content

Conversation

@uhfath
Copy link
Contributor

@uhfath uhfath commented Mar 3, 2025

When initializing NATS using IServiceCollection.AddNatsClient one has to specify a pool size in a callback, which doesn't support passing IServiceProvider. This involves setting pool size upfront as a constant or reading it from IConfiguration directly with something like IConfiguration.GetSection(...).Get<...>().
This PR retains an ability to specify pool size constantly as it is now without breaking changes. And also adds an ability to use IServiceProvider which helps in cases where pool size is defined in one of app options. Something like:

.WithPoolSize(sp => sp.GetService<IOptions<AppOption>>().Value.NATSPoolSize)

But because of this there will be no more SingleConnectionFactory and PooledConnectionFactory will be always used even if pool size is 1.
This might come with a performance impact in very high load cases since there is another layer of delegates added.
But it should be negligible.

@mtmk
Copy link
Member

mtmk commented Mar 7, 2025

please merge main. fixes build.

@uhfath uhfath force-pushed the pool_size_func_fixed_and_signed branch from 05bd88e to 98c14e6 Compare March 8, 2025 07:52
@uhfath
Copy link
Contributor Author

uhfath commented Mar 8, 2025

Done.

@mtmk
Copy link
Member

mtmk commented Mar 11, 2025

cc @rickdotnet

Copy link
Member

@mtmk mtmk left a comment

Choose a reason for hiding this comment

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

LGTM thanks @uhfath

@mtmk mtmk merged commit 7736cf9 into nats-io:main Mar 11, 2025
10 checks passed
mtmk added a commit that referenced this pull request Mar 12, 2025
* Add support for Direct Get API with key in subject (#771)
* Add Metadata to KV Bucket (#741)
* Added an ability to specify pool size with a callback using IServiceProvider (#757)
* Add NatsPayloadTooLargeException class (#761)
* Make the parameter-less StreamConfig constructor public (#768)
* Release 2.5.10-preview.1 (#766)
* Fix reconnect getting stuck (#758)
* Fix task tracking (#764)
* Fix Windows build (#765)
@mtmk mtmk mentioned this pull request Mar 12, 2025
mtmk added a commit that referenced this pull request Mar 12, 2025
* Add support for Direct Get API with key in subject (#771)
* Add Metadata to KV Bucket (#741)
* Added an ability to specify pool size with a callback using IServiceProvider (#757)
* Add NatsPayloadTooLargeException class (#761)
* Make the parameter-less StreamConfig constructor public (#768)
* Release 2.5.10-preview.1 (#766)
* Fix reconnect getting stuck (#758)
* Fix task tracking (#764)
* Fix Windows build (#765)
@mtmk mtmk added this to the v2.5.11 milestone Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants