Skip to content

Add Prioritized Priority Consumer Policy#965

Merged
mtmk merged 4 commits into
mainfrom
2.12/prioritized-priority-policy
Oct 1, 2025
Merged

Add Prioritized Priority Consumer Policy#965
mtmk merged 4 commits into
mainfrom
2.12/prioritized-priority-policy

Conversation

@mtmk

@mtmk mtmk commented Sep 26, 2025

Copy link
Copy Markdown
Member

This pull request adds support for the "prioritized" priority policy for JetStream consumers as described in ADR-42, enabling message delivery prioritization based on a specified priority value. It updates the consumer configuration, request models, and fetch options to include a Priority field used when the "prioritized" policy is set. The changes are validated and tested with new unit tests.

Breaking change:

PriorityPolicy on consumer config is now implemented as an enum an it would break applications using this field as string before. Applications not using this field won't be affected.

Support for prioritized priority policy:

  • Added "prioritized" as a valid value for PriorityPolicy in ConsumerConfig, and updated validation to accept it. [1] [2]
  • Added a Priority property to ConsumerGetnextRequest and NatsJSPriorityGroupOpts, allowing clients to specify delivery priority (0-9, with 0 as highest). [1] [2]
  • Updated NatsJSConsumer to pass the Priority value from fetch options into the consumer request. [1] [2] [3]

Testing and validation:

  • Added unit tests to verify correct behavior when using the "prioritized" policy and priority values, and to ensure the policy is accepted in consumer creation.

@mtmk
mtmk requested review from Copilot and scottf September 26, 2025 12:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request implements support for the "prioritized" priority policy for JetStream consumers, enabling message delivery prioritization based on a specified priority value (0-9, with 0 being highest priority).

  • Adds "prioritized" as a valid priority policy option alongside existing "overflow" and "pinned_client" policies
  • Introduces Priority field to consumer request models and fetch options for specifying delivery priority
  • Updates consumer validation logic and includes comprehensive unit tests for the new functionality

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/NATS.Client.JetStream.Tests/PriorityGroupTest.cs Adds unit tests for prioritized policy functionality and validation
src/NATS.Client.JetStream/NatsJSOpts.cs Adds Priority property to NatsJSPriorityGroupOpts for specifying message priority
src/NATS.Client.JetStream/NatsJSContext.Consumers.cs Updates validation to accept "prioritized" policy and improves error message
src/NATS.Client.JetStream/NatsJSConsumer.cs Passes Priority value from fetch options to consumer requests
src/NATS.Client.JetStream/Models/ConsumerGetnextRequest.cs Adds Priority field to consumer request model with validation
src/NATS.Client.JetStream/Models/ConsumerConfig.cs Updates documentation to mention "prioritized" policy

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@mtmk mtmk added the breaking label Sep 30, 2025

if (config.PriorityPolicy is "pinned_client")
{
throw new NotImplementedException("Pinned clients are not supported yet.");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

pinned_client wan't implemented anyway, so just removed it here.

}

// TODO: enum these values?
if (config.PriorityPolicy != null && config.PriorityPolicy != "none" && config.PriorityPolicy != "overflow" && config.PriorityPolicy != "pinned_client")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

don't need this check any more. it's an enum now.


/// <summary>
/// Specifies the priority policy for consumer message selection, such as prioritizing <c>overflow</c> or <c>pinned_client</c>.
/// Specifies the priority policy for consumer message selection.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no need for documenting values. it's an enum now. it's a breaking change but since this is a fairly new feature, i don't expect many applications would be affected by it. required recompilation but the fix should be straight forward.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, this is fine. I've done the same on brand new things.

}

[Fact]
public void ConsumerConfigPriorityPolicy_null_test()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we also have a test for null where it should not be serialized onto the wire at all when null.

# Conflicts:
#	src/NATS.Client.JetStream/NatsJSJsonSerializer.cs
#	tests/NATS.Client.JetStream.Tests/EnumJsonTests.cs

@scottf scottf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM


/// <summary>
/// Specifies the priority policy for consumer message selection, such as prioritizing <c>overflow</c> or <c>pinned_client</c>.
/// Specifies the priority policy for consumer message selection.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, this is fine. I've done the same on brand new things.

[System.Text.Json.Serialization.JsonPropertyName("priority")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
[System.ComponentModel.DataAnnotations.Range(0, 9)]
public byte Priority { get; set; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

when these are serialized, are the names lowercased?
probably what this is for

 new JsonStringEnumConverter<ConsumerConfigPriorityPolicy (JsonNamingPolicy.SnakeCaseLower),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I assume None does not get written either.

@mtmk
mtmk merged commit db6633b into main Oct 1, 2025
21 checks passed
@mtmk
mtmk deleted the 2.12/prioritized-priority-policy branch October 1, 2025 07:52
mtmk added a commit that referenced this pull request Oct 1, 2025
* Add Prioritized Priority Consumer Policy (#965)
* Add persist mode support (#964)
* Add support for message schedules (#963)
* Add Atomic Publish Support (#962)
* Counter support for server v2.12 (#960)
@mtmk mtmk mentioned this pull request Oct 1, 2025
mtmk added a commit that referenced this pull request Oct 1, 2025
* Add Prioritized Priority Consumer Policy (#965)
* Add persist mode support (#964)
* Add support for message schedules (#963)
* Add Atomic Publish Support (#962)
* Counter support for server v2.12 (#960)
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.

3 participants