Skip to content

Add support for multiple filters in consumer grous#40

Open
mtmk wants to merge 6 commits intomainfrom
Multiple-Subscription-Filters
Open

Add support for multiple filters in consumer grous#40
mtmk wants to merge 6 commits intomainfrom
Multiple-Subscription-Filters

Conversation

@mtmk
Copy link
Collaborator

@mtmk mtmk commented Mar 3, 2026

  • Static config uses Filters (string array) only — removed single Filter property
  • Elastic config uses PartitioningFilters array of {filter, partitioning_wildcards} pairs. removed separate Filter/Filters/PartitioningWildcards properties
  • Full-subject partitioning uses empty partitioning_wildcards array [] instead of [-1] sentinel
  • Partition filter format is {partition}.{filter} (e.g., 0.orders.*) instead of {partition}.>

Cross-implementation compatibility

JSON config stored in NATS KV is now interoperable with Go (synadia-io/orbit.go#44):

  • Static config JSON: "filters" string array (no "filter" field)
  • Elastic config JSON: "partitioning_filters" array of {"filter": "...", "partitioning_wildcards": [...]} objects (no separate "filter"/"partitioning_wildcards" fields)
  • Full-subject partitioning: empty partitioning_wildcards array [] — Go never had [-1], so this removes the interop gap
  • Consumer subscription subjects: {partition}.{filter} format matches Go behavior

mtmk added 3 commits March 3, 2026 13:49
… configurations

Refactored filtering logic, added utility methods, extended validations, updated related tests, and enhanced handling of wildcard-based partitioning.
@mtmk
Copy link
Collaborator Author

mtmk commented Mar 3, 2026

Hey @colprog, does this make sense to you? thanks

@colprog
Copy link
Contributor

colprog commented Mar 3, 2026

Hi @mtmk , Thanks for coming up with a patch so quickly. This is exactly what I wanted. If I understand correctly, using [-1] as partitioningWildcards will require nats-server 2.12+?

@mtmk
Copy link
Collaborator Author

mtmk commented Mar 4, 2026

hey @colprog

Hi @mtmk , Thanks for coming up with a patch so quickly. This is exactly what I wanted. If I understand correctly, using [-1] as partitioningWildcards will require nats-server 2.12+?

spot on! yes, server must be 2.12+ hence the test failures on 2.10 and 2.11. fixing them now. edit: tests are fixed.

@mtmk
Copy link
Collaborator Author

mtmk commented Mar 4, 2026

@jnmoyne @piotrpio heads up, this PR adds two .NET-only extensions to PCGroups that aren't in orbit.go yet:

  1. Multiple filters per consumer group (Filters property alongside the existing Filter)
  2. [-1] sentinel for partition-by-full-subject: a convention we introduced here that uses {{Partition}} without wildcard positions (requires NATS server 2.12+)

Would be good to get your thoughts on whether these make sense to standardize across implementations, or if you'd approach them differently in Go.

@mtmk mtmk requested review from jnmoyne and piotrpio March 4, 2026 11:00
@mtmk mtmk marked this pull request as ready for review March 4, 2026 11:02
@mtmk mtmk self-assigned this Mar 4, 2026
@jnmoyne
Copy link

jnmoyne commented Mar 4, 2026

This is great, thanks! Actually there have been a few changes to the Go implementation lately and it's due for a new release, and we should synchronize the two. Multi-filter has actually already be done in Go :) synadia-io/orbit.go#44. The one difference however is since the plan is to cut a new release (as soon at that last PR gets merged in) I decided to add Filters and remove Filter since (talking from experience here :)) it can get irritating and source of issues to keep the old single filter field around, since PCG is so new might as well break backwards compatibility but do it right with just the array. So .net should do the same so they are interoperable (there's actually also now a Java version that just got released, and that uses the new 'array of filters only' version of the config so it interoperates with Go, and with .net once you make that change.

I like the idea of -1 for partition on the whole subject, so I'll add that to Go (and Java).

Note that there are other PRs that have merged to the Go version since the original release with some small improvements that you should check out.

@colprog
Copy link
Contributor

colprog commented Mar 4, 2026

Using -1 for partition, we could support orders.> or even > as filter, Is this something we should pursue is a future release?

@jnmoyne
Copy link

jnmoyne commented Mar 5, 2026

I would rather have PartitioningWildcards array being empty means it partitions over the whole subject (rather than have a single -1 entry in that array. We can get all versions to the same level (all the changes to the Go version plus empty PartitioningWildcards) and then make a release in all languages (where they can interoperate together).

…th `NatsPcgPartitioningFilter`, simplify validations, and update related tests.
@mtmk
Copy link
Collaborator Author

mtmk commented Mar 5, 2026

thanks @jnmoyne

I think all the feedback is addressed:

JSON config in KV should now be interoperable with Go and Java.

@mtmk
Copy link
Collaborator Author

mtmk commented Mar 5, 2026

hey @colprog thanks for getting the ball rolling on this one. Please let us know how you get on with the changes and please fell free to review the code if you have some time.

@colprog
Copy link
Contributor

colprog commented Mar 5, 2026

Thanks, The changes looks good.

Copy link

@jnmoyne jnmoyne left a comment

Choose a reason for hiding this comment

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

LGTM (after the changes since my last review)

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.

Support Multiple Subscription Filters in PCGroups

3 participants