Skip to content

Conversation

@mtmk
Copy link
Member

@mtmk mtmk commented Sep 24, 2025

Support implementation of ADR-49

This pull request adds support for the JetStream message counter feature introduced in NATS server v2.12. It introduces a new property to enable message counters in stream configurations, updates the publish acknowledgment response to include the counter value, and adds comprehensive tests to verify the new functionality and error handling.

JetStream message counter support:

  • Added the AllowMsgCounter property to the StreamConfig model, allowing streams to enable or disable message counters. This property is serialized as allow_msg_counter and is supported from server v2.12.
  • Updated the PubAckResponse model to include an optional Value property (serialized as val), which returns the current counter value when publishing messages with counter headers.

Testing:

  • Added a new CounterTest class to verify message counter functionality, including incrementing, decrementing, using multiple counters, and ensuring proper error handling when the feature is disabled.

@mtmk mtmk self-assigned this Sep 24, 2025
@mtmk mtmk added the priority label Sep 24, 2025
@mtmk mtmk requested a review from Copilot September 24, 2025 12:33
@mtmk mtmk marked this pull request as ready for review September 24, 2025 12:33
@mtmk mtmk requested a review from scottf September 24, 2025 12:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements JetStream message counter support for NATS server v2.12, enabling streams to track and increment/decrement counters via message headers. The implementation follows ADR-49 specifications by adding configuration options and response value handling.

  • Added AllowMsgCounter property to StreamConfig for enabling counter functionality
  • Enhanced PubAckResponse to include counter value in publish acknowledgments
  • Comprehensive test coverage for counter operations and error scenarios

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/NATS.Client.JetStream/Models/StreamConfig.cs Adds AllowMsgCounter boolean property to enable message counters in stream configuration
src/NATS.Client.JetStream/Models/PubAckResponse.cs Adds optional Value property to return counter values in publish acknowledgments
tests/NATS.Client.JetStream.Tests/CounterTest.cs Implements comprehensive test suite covering counter operations, error handling, and feature validation

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

@mtmk mtmk requested a review from Copilot September 24, 2025 12:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


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

@mtmk mtmk mentioned this pull request Sep 24, 2025
Copy link
Contributor

@scottf scottf 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 4b3d2a1 into main Sep 25, 2025
18 checks passed
@mtmk mtmk deleted the 2.12/support-for-JetStream-Distributed-Counter-CRDT branch September 25, 2025 08:45
/// <remarks>Supported by server v2.12</remarks>
[System.Text.Json.Serialization.JsonPropertyName("allow_msg_counter")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public bool AllowMsgCounter { get; set; }
Copy link
Member Author

Choose a reason for hiding this comment

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

this should be nullable

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