feat: port session 05 — Subscription Index (sublist)

Port trie-based subject matching engine (81 features, 74 tests).
Includes SubscriptionIndex with cache, wildcard matching (*/>),
queue subscription groups, reverse match, notifications, stats,
and subject validation utilities. Also adds minimal Subscription
and NatsClient stubs needed by the index.
This commit is contained in:
Joseph Doherty
2026-02-26 12:11:06 -05:00
parent b8f2f66d45
commit ed78a100e2
6 changed files with 2827 additions and 7 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,77 @@
// Copyright 2012-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Adapted from server/client.go (subscription struct) in the NATS server Go source.
namespace ZB.MOM.NatsNet.Server.Internal;
/// <summary>
/// Represents a client subscription in the NATS server.
/// Mirrors the Go <c>subscription</c> struct from client.go.
/// This is a minimal stub; full client integration will be added in later sessions.
/// </summary>
public sealed class Subscription
{
/// <summary>The subject this subscription is listening on.</summary>
public byte[] Subject { get; set; } = [];
/// <summary>The queue group name, or null/empty for non-queue subscriptions.</summary>
public byte[]? Queue { get; set; }
/// <summary>The subscription identifier.</summary>
public byte[]? Sid { get; set; }
/// <summary>Queue weight for remote queue subscriptions.</summary>
public int Qw;
/// <summary>Closed flag (0 = open, 1 = closed).</summary>
private int _closed;
/// <summary>The client that owns this subscription. Null in test/stub scenarios.</summary>
public NatsClient? Client { get; set; }
/// <summary>Marks this subscription as closed.</summary>
public void Close() => Interlocked.Exchange(ref _closed, 1);
/// <summary>Returns true if this subscription has been closed.</summary>
public bool IsClosed() => Interlocked.CompareExchange(ref _closed, 0, 0) == 1;
}
/// <summary>
/// Represents the kind of client connection.
/// Mirrors Go's <c>clientKind</c> enum.
/// This is a minimal stub; full implementation in later sessions.
/// </summary>
public enum ClientKind
{
Client = 0,
Router = 1,
Gateway = 2,
System = 3,
Leaf = 4,
JetStream = 5,
Account = 6,
}
/// <summary>
/// Minimal client stub for subscription routing.
/// Full implementation will be added in later sessions.
/// </summary>
public class NatsClient
{
/// <summary>The kind of client connection.</summary>
public ClientKind Kind { get; set; }
/// <summary>Whether this is a hub leaf node. Stub for now.</summary>
public virtual bool IsHubLeafNode() => false;
}