We're excited to announce the release of NATS.Net v2.1.0. This version brings performance improvements, numerous fixes, and a few necessary breaking changes to enhance unit testing and async events:
- Send buffer performance improvements using I/O pipelines
- Enhanced interface accessibility for simplified unit testing
- Added capability for asynchronous event handling
- Support for keyed dependency injection
- And bug fixes
What's Changed
- Expose ReplyTo on NatsJSMsg by @rickdotnet in #314
- Suggested fixes to interfaces by @sspates in #297
- Use System.IO.Pipelines for sending by @caleblloyd in #303
- NatsSub cancellation token race fix by @mtmk in #325
- Object store name check fix by @mtmk in #327
- micro-optimizations in ProtocolWriter by @caleblloyd in #329
- Support Keyed DI services in .NET 8 by @rickdotnet in #331
- Nullability review for models by @mnmr in #332
- Addition of factories for better testability. by @sspates in #330
- Ordered consumer optimizations by @mtmk in #336
- TLS auth timeout by @mtmk in #339
- Log connection failure as warning by @jasper-d in #343
- pipe reader: don't mark commands as consumed until pending=0 by @caleblloyd in #347
- Async event handlers by @mnmr in #324
- Updated interface to include Async events. by @sspates in #353
- Fix unnecessary error log on dispose by @mtmk in #354
- Ping command as value task source by @mtmk in #358
- Added deliver_group to consumer config by @mtmk in #366
- Send buffer changes by @mtmk in #346
- Expose Headers on NatsSvcMsg by @niklasfp in #371
- Fix NatsSvcServer start time format so that it's no longer culture aware by @niklasfp in #374
- Reject payloads over the threshold set by server by @mtmk in #378
- Publish - avoid async state machine when possible by @caleblloyd in #373
- Send buffer fix by @mtmk in #380
- Buffer defaults avoiding LOH by @mtmk in #383
- Hosting keyed services fixes by @mtmk in #386
- Add nkey and sha512 micro benchmarks and sanity check tests by @niklasfp in #389
- Fixed base64 decode buffer size by @mtmk in #387
New Contributors
- @rickdotnet made their first contribution in #314
- @sspates made their first contribution in #297
- @mnmr made their first contribution in #332
- @niklasfp made their first contribution in #371
Full Changelog: v2.0.3...v2.1.0
Send Buffer Performance Improvements
Thanks to @caleblloyd's outstanding contributions and the awesome support from @to11mtm and @stebet, we've enhanced the send buffer's performance by utilizing IO pipelines, resulting in better memory usage and garbage collection efficiency.
v2.0.3
Method | Iter | Mean | Error | StdDev | Gen0 | Allocated |
---|---|---|---|---|---|---|
PublishAsync | 64 | 172.0 us | 26.54 us | 1.45 us | - | 803 B |
PublishAsync | 512 | 469.7 us | 25.64 us | 1.41 us | 0.9766 | 18061 B |
PublishAsync | 1024 | 684.6 us | 62.52 us | 3.43 us | 1.9531 | 37606 B |
v2.1.0
Method | Iter | Mean | Error | StdDev | Allocated |
---|---|---|---|---|---|
PublishAsync | 64 | 130.9 us | 17.24 us | 0.95 us | 380 B |
PublishAsync | 512 | 277.5 us | 10.69 us | 0.59 us | 381 B |
PublishAsync | 1024 | 444.9 us | 7.15 us | 0.39 us | 356 B |
Breaking Changes and Migration Guide
Event handlers
- Event handlers on connection object are now asynchronous and you would need to make code changes if you've been using them. Also one of the event's name has changed from 'OnError' to 'MessageDropped`:
nats.MessageDropped += async (_, e) =>
{
await File.AppendAllTextAsync("c:/tmp/log.txt", $"[DROP] {e.Subject}: {e.Data}\n");
};
- The way the events are dispatched has also changed to use a channel hence there maybe a delay receiving the event in your handlers.
See #324 for more details.
Other minor breaking changes
- Nullability review for models changed quite a few of the (mainly) JetStream model classes for better compiler support and developer experience. (#332)
- If you're relying on log severity on reconnect messages please check #343 for details as
Failed to connect NATS {Url}
messages are now logged as warnings instead of errors.
Thank you
Also a huge thanks to our contributors and community for their amazing work and support! 🙏
Join our community chat rooms if you have any questions either on slack.nats.io dotnet channel or here on GitHub!
Don't forget to check out the documentation for guides and examples.
Additionally check out NATS by example - An evolving collection of runnable, cross-client reference examples for NATS.
Happy coding! ❤️
Nuget Packages
NATS.Net
This is the main meta package containing all other packages except serialization.
dotnet add package NATS.Net --version 2.1.0
If you are not deploying Native AOT you can also use ad-hoc JSON serialization:
dotnet add package NATS.Client.Serializers.Json --version 2.1.0
Individual Packages
dotnet add package NATS.Client.Core --version 2.1.0
dotnet add package NATS.Client.Hosting --version 2.1.0
dotnet add package NATS.Client.JetStream --version 2.1.0
dotnet add package NATS.Client.KeyValueStore --version 2.1.0
dotnet add package NATS.Client.ObjectStore --version 2.1.0
dotnet add package NATS.Client.Services --version 2.1.0
dotnet add package NATS.Client.Serializers.Json --version 2.1.0