Skip to content

Add support for Consumer Create Action #497

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

Merged
merged 7 commits into from
May 15, 2024

Conversation

Ivandemidov00
Copy link
Contributor

@Ivandemidov00 Ivandemidov00 commented May 11, 2024

Resolves #475

@Ivandemidov00 Ivandemidov00 marked this pull request as draft May 11, 2024 10:50
@Ivandemidov00 Ivandemidov00 marked this pull request as ready for review May 11, 2024 10:58
@Ivandemidov00
Copy link
Contributor Author

Fixed problem with serialize .net8 and test on create publisher action

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.

looks good over all, just a suggestion about removing CreateOrUpdate from the enum since absence of the action field would mean the same thing as an empty string.

#else
[System.Text.Json.Serialization.JsonConverter(typeof(NatsJSJsonStringEnumConverter<ConsumerCreateRequestAction>))]
#endif
public ConsumerCreateRequestAction Action { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Could we make this optional so that we don't have to deal with net8 serialization exception for an empty value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that was one of the ideas. In this case, the property will sample be ignored and NatsJSJsonStringEnumConverter will be less strict

Create = 0,
Update = 1,
[EnumMember(Value = "")]
CreateOrUpdate = 2,
Copy link
Member

Choose a reason for hiding this comment

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

we can remove this option if action is optional.

}
}
#else
internal class NatsJSJsonStringEnumConverter<TEnum> : JsonConverter<TEnum>
Copy link
Member

Choose a reason for hiding this comment

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

is this for net8? I guess we can leave it as camelCase and not need this class?

@@ -33,31 +33,25 @@ public partial class NatsJSContext : INatsJSContext
CancellationToken cancellationToken = default)
{
ThrowIfInvalidStreamName(stream);
return await CreateOrUpdateConsumerInternalAsync(stream, config, ConsumerCreateRequestAction.CreateOrUpdate, cancellationToken);
Copy link
Member

Choose a reason for hiding this comment

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

we could make action nullable here.


namespace NATS.Client.JetStream.Models;

public enum ConsumerCreateRequestAction
Copy link
Member

Choose a reason for hiding this comment

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

what do you think of ConsumerCreateAction as the name? more succinct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, think it's good too. Renamed

@mtmk mtmk self-assigned this May 13, 2024
Демидов Иван and others added 2 commits May 14, 2024 21:34
ConsumerCreateAction enum has been updated to include a default value.
Previously nullable instances of this enum have been updated to
leverage the default value instead. The necessary adjustments have been
made in the related JSON serializer, consumer creation methods, and
tests to reflect this change.

When using nullable enum to accomodate for the absence of 'action' property
in JSON, we are forced to remove the type constraints on the serializer
class which is not ideal and leaves us to deal with null values.

Instead, having the default value of the enum as the first element lets
us using 'default' keyword instead of null in calls, making it less confusing.
@mtmk
Copy link
Member

mtmk commented May 15, 2024

@Ivandemidov00 thanks for the updates. Just made a change to enum default and removed the nullable marking. I think it's easier to reason with this way.

@mtmk mtmk requested a review from caleblloyd May 15, 2024 09:34
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 @Ivandemidov00
(will wait for another review because of my changes)


public enum ConsumerCreateAction
{
Default = 0,
Copy link
Collaborator

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 make the default descriptive? I.e. CreateOrUpdate = 0 instead of Default = 0?

Or is it best to leave it vague as the NATS Server can decide the default?

Copy link
Collaborator

@caleblloyd caleblloyd left a comment

Choose a reason for hiding this comment

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

LGTM

@mtmk mtmk merged commit f6c6419 into nats-io:main May 15, 2024
10 checks passed
mtmk added a commit that referenced this pull request May 23, 2024
* Change ConsumerConfig AckPolicy default to Explicit (#490)
* Add support for Consumer Create Action (#497)
* Add `IsSuccess` extension method for PubAckResponse (#493)
* Watch Multiple KV Filters (#485)
* FIX : PurgeDeletesAsync hangs if KV Bucket is already empty (#489)
* Fix NUID sequence (#488)
@mtmk mtmk mentioned this pull request May 23, 2024
mtmk added a commit that referenced this pull request May 23, 2024
* Release 2.2.2

* Change ConsumerConfig AckPolicy default to Explicit (#490)
* Add support for Consumer Create Action (#497)
* Add `IsSuccess` extension method for PubAckResponse (#493)
* Watch Multiple KV Filters (#485)
* FIX : PurgeDeletesAsync hangs if KV Bucket is already empty (#489)
* Fix NUID sequence (#488)

* Fixed test
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.

Consumer Action API
3 participants