-
Notifications
You must be signed in to change notification settings - Fork 58
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
Serialization API proposal cont. #177
Conversation
This is the continuation of the previous proposal where simplified the serialization APIs and made them compatible with native AOT deployments. With this change, we make it more obvious where to pass the serializer into various calls. We also made the interface generic to make it easier to implement in certain scenarios.
@jasper-d you'd be interested 💯 |
I'll take a look |
# Conflicts: # src/NATS.Client.JetStream/NatsJSStream.cs # src/NATS.Client.KeyValueStore/INatsKVWatcher.cs # src/NATS.Client.KeyValueStore/Internal/NatsKVWatcher.cs # src/NATS.Client.KeyValueStore/NatsKVStore.cs # src/NATS.Client.ObjectStore/NatsObjStore.cs # src/NATS.Client.Services/NatsSvcServer.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I think this is a good compromise to support both, serializers passed directly and serializers attached to a connection.
string subject, | ||
TRequest? data, | ||
NatsHeaders? headers = default, | ||
INatsSerializer<TRequest>? requestSerializer = default, | ||
INatsSerializer<TReply>? replySerializer = default, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to split INatsSerializer<T>
into I(Nats)Serializer<T>
and I(Nats)Deserializer<T>
now? Presumably one is often not going to send and receive the same type but the current interface requires an implementation for both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which then also raises the question if it wouldn't be better (and feasible) to just use Action<IBufferWriter<byte>, T>
and Func<ReadOnlySequence<byte>, T>
so that clients don't have to implement the interface if they already have a suitable serializer that matches the delegates signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds ok but I'd like to see what @caleblloyd would say here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splitting into I(Nats)Serializer<T>
and I(Nats)Deserializer<T>
makes sense to me
The Action
/ Func
seems a little non-standard - it may map cleanly to some Serializer/Deseriaizers such as GRPC, but not others, such as JsonSerializer. It should be trivial to use a helper function to create a static I(Nats)Serializer<T>
and I(Nats)Deserializer<T>
from an Action / Func though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree we can split the interface but I'm leaning towards interfaces too rather than action/func approach. I believe interface would be more developer friendly in general.
Co-authored-by: Jasper <[email protected]>
Co-authored-by: Jasper <[email protected]>
# Conflicts: # sandbox/Example.JetStream.PullConsumer/Program.cs # src/NATS.Client.JetStream/INatsJSConsume.cs # src/NATS.Client.JetStream/INatsJSFetch.cs # src/NATS.Client.JetStream/Internal/NatsJSConsume.cs # src/NATS.Client.JetStream/NatsJSConsumer.cs # src/NATS.Client.JetStream/NatsJSContext.cs # src/NATS.Client.ObjectStore/NatsObjStore.cs # tests/NATS.Client.CheckNativeAot/Program.cs # tests/NATS.Client.JetStream.Tests/ConsumerConsumeTest.cs # tests/NATS.Client.JetStream.Tests/ConsumerFetchTest.cs # tests/NATS.Client.JetStream.Tests/ConsumerNextTest.cs # tests/NATS.Client.JetStream.Tests/JetStreamTest.cs # tests/NATS.Client.JetStream.Tests/PublishTest.cs
I will be updating the docs in the release prep PR |
I like the interface splitting, but might I suggest some clarity on naming:
Then for parameter naming what is your opinion of calling all of the params that deal with Serialize/Deseialize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple docs fixes, then LGTM!
Co-authored-by: Caleb Lloyd <[email protected]>
Co-authored-by: Caleb Lloyd <[email protected]>
https://github.com/nats-io/nats.net.v2/blob/serialization-api-change-proposal-2/docs/documentation/serialization.md
(Docs to be updated in a later PR)
Summary
serializer
parameter to all publish, subscribe and consume calls alikeINatsSerializer<T>
INatsSerializerRegistry
for connection wide serialization settings<T?>
-><T>
Details
This is the continuation of the previous proposal where simplified the serialization APIs and made them compatible with native AOT deployments.
With this change, we make it more obvious where to pass the serializer into various calls. We also made the interface generic to make it easier to implement in a type safe manner.
The main change is that the serializer option is removed from
NatsSubOpts
andNatsPubOpts
classes and became a parameter in publish and subscribe calls (as well as in all JS / KV / Obj / Svc etc. calls):This makes it easier to pass in different serializers in every call, especially in native AOT deployments.
We also introduce a serializer registry concept to be used as a connection wide serialization mechanism. This was necessary with
INatsSerializer<T>
being generic and since we can't know the type in advance. It's very simple and can be passed in withNatsOpts.Serializers
property:So we have the additional flexibility with
INatsSerializerRegistry
on top of being able to chain multipleINatsSerializer<T>
s.Also fixes #142