-
Notifications
You must be signed in to change notification settings - Fork 49
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
JetStream API clean-up #212
Conversation
* Removed opinionated method overloads for create consumer and stream. * Removed publish overload for sending empty messages. Doesn't feel like a common operation in JS. Removed to reduce the API footprint. * A few format fixes. * A couple of potential test flapper timeout fixes.
I do miss the simplicity, it's no longer clear what settings are actually required. Would it make sense to provide some static helpers/extensions
That way if I want an R3 stream I could do
Much simpler in my opinion than having to look into the detials of the record to discover that Also - not sure how often people create Ephemeral consumers explicitly. Might be worth making the helpers explicit for It takes some deep knowledge to know that you must supply |
Any interest in shortening the models |
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.
LGTM
I like the change to |
# Conflicts: # src/NATS.Client.ObjectStore/NatsObjContext.cs
@@ -19,7 +19,7 @@ | |||
|
|||
var js = new NatsJSContext(nats); | |||
|
|||
var consumer = await js.CreateConsumerAsync(new ConsumerCreateRequest { StreamName = "s1", Config = new ConsumerConfiguration { Name = "c1", DurableName = "c1", AckPolicy = ConsumerConfigurationAckPolicy.@explicit } }); | |||
var consumer = await js.CreateConsumerAsync("s1", new ConsumerConfiguration { Name = "c1", DurableName = "c1", AckPolicy = ConsumerConfigurationAckPolicy.@explicit }); |
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.
Framework guidelines dictate that enum names should be Pascal cased -- then you could avoid the ugly at escape on explicit.
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.
Unfortunately I had an issue with the JSON serializer not using the attributed name then had to make it same case as the JSON property to make it work.
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.
For S.T.Json, the way I do this [net8] is:
builder.Services
.AddJsonOptions(
options =>
{
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter<PassportIssuingSettings>(JsonNamingPolicy.CamelCase));
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
options.JsonSerializerOptions.TypeInfoResolver = PassportJsonSerializationContext.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.
PassportJsonSerializationContext is my source generator context for my structures. I'd imagine you guys are using that code path too?
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.
Here's the partial context I declared:
[JsonSerializable(typeof(Passport))]
[JsonSerializable(typeof(PassportIssuingSettings))]
[JsonSerializable(typeof(Visa))]
[JsonSerializable(typeof(ValidationProblemDetails))]
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
public partial class PassportJsonSerializationContext : JsonSerializerContext
{
}
This is for AOT ready serialization etc.
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.
Tbh, some of my declarations are probably redundant - anything in the AddJsonOptions setup can probably be applied to the context instead. I went through an evolution making things work from net6 to net8 :/ - but it works. My enums are serialized to camel case, declared in dotnet as pascal.
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.
Yes we have a context, that attribute solution looks promising. Do you still have to set the option?
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 think the option is only for when you don't use a context. I started out that way, then added a context later but never took away the option. I assume the attributes on the context are enough :) But maybe the converter registration only works in options. A quick experiment on your side should tell you quickly enough.
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.
Oh, so you can pass in options director to the context ctor too:
_jsonSerializationContext = new PassportJsonSerializationContext(
new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters = { }
});
Then you don't need the entry point AddJsonOptions fluff.
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.
hmmm. it doesn't seem to work (see example https://github.com/mtmk/example-json-enum)
Need to implement a convertor I think.
/cc @Jarema