feat: execute post-baseline jetstream parity plan
This commit is contained in:
@@ -52,6 +52,7 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
private readonly RouteManager? _routeManager;
|
||||
private readonly GatewayManager? _gatewayManager;
|
||||
private readonly LeafNodeManager? _leafNodeManager;
|
||||
private readonly InternalClient? _jetStreamInternalClient;
|
||||
private readonly JetStreamService? _jetStreamService;
|
||||
private readonly JetStreamApiRouter? _jetStreamApiRouter;
|
||||
private readonly StreamManager? _jetStreamStreamManager;
|
||||
@@ -97,6 +98,7 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
public string? ClusterListen => _routeManager?.ListenEndpoint;
|
||||
public string? GatewayListen => _gatewayManager?.ListenEndpoint;
|
||||
public string? LeafListen => _leafNodeManager?.ListenEndpoint;
|
||||
public InternalClient? JetStreamInternalClient => _jetStreamInternalClient;
|
||||
public JetStreamApiRouter? JetStreamApiRouter => _jetStreamApiRouter;
|
||||
public int JetStreamStreams => _jetStreamStreamManager?.StreamNames.Count ?? 0;
|
||||
public int JetStreamConsumers => _jetStreamConsumerManager?.ConsumerCount ?? 0;
|
||||
@@ -107,6 +109,8 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
|
||||
public IEnumerable<Auth.Account> GetAccounts() => _accounts.Values;
|
||||
public bool HasRemoteInterest(string subject) => _globalAccount.SubList.HasRemoteInterest(subject);
|
||||
public bool HasRemoteInterest(string account, string subject)
|
||||
=> GetOrCreateAccount(account).SubList.HasRemoteInterest(account, subject);
|
||||
public bool TryCaptureJetStreamPublish(string subject, ReadOnlyMemory<byte> payload, out PubAck ack)
|
||||
{
|
||||
if (_jetStreamPublisher != null && _jetStreamPublisher.TryCapture(subject, payload, out ack))
|
||||
@@ -390,7 +394,9 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
{
|
||||
_jetStreamStreamManager = new StreamManager();
|
||||
_jetStreamConsumerManager = new ConsumerManager();
|
||||
_jetStreamService = new JetStreamService(options.JetStream);
|
||||
var jsClientId = Interlocked.Increment(ref _nextClientId);
|
||||
_jetStreamInternalClient = new InternalClient(jsClientId, ClientKind.JetStream, _systemAccount);
|
||||
_jetStreamService = new JetStreamService(options.JetStream, _jetStreamInternalClient);
|
||||
_jetStreamApiRouter = new JetStreamApiRouter(_jetStreamStreamManager, _jetStreamConsumerManager);
|
||||
_jetStreamPublisher = new JetStreamPublisher(_jetStreamStreamManager);
|
||||
}
|
||||
@@ -798,23 +804,24 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public void OnLocalSubscription(string subject, string? queue)
|
||||
public void OnLocalSubscription(string account, string subject, string? queue)
|
||||
{
|
||||
_routeManager?.PropagateLocalSubscription(subject, queue);
|
||||
_gatewayManager?.PropagateLocalSubscription(subject, queue);
|
||||
_leafNodeManager?.PropagateLocalSubscription(subject, queue);
|
||||
_routeManager?.PropagateLocalSubscription(account, subject, queue);
|
||||
_gatewayManager?.PropagateLocalSubscription(account, subject, queue);
|
||||
_leafNodeManager?.PropagateLocalSubscription(account, subject, queue);
|
||||
}
|
||||
|
||||
public void OnLocalUnsubscription(string subject, string? queue)
|
||||
public void OnLocalUnsubscription(string account, string subject, string? queue)
|
||||
{
|
||||
_routeManager?.PropagateLocalUnsubscription(subject, queue);
|
||||
_gatewayManager?.PropagateLocalUnsubscription(subject, queue);
|
||||
_leafNodeManager?.PropagateLocalUnsubscription(subject, queue);
|
||||
_routeManager?.PropagateLocalUnsubscription(account, subject, queue);
|
||||
_gatewayManager?.PropagateLocalUnsubscription(account, subject, queue);
|
||||
_leafNodeManager?.PropagateLocalUnsubscription(account, subject, queue);
|
||||
}
|
||||
|
||||
private void ApplyRemoteSubscription(RemoteSubscription sub)
|
||||
{
|
||||
_globalAccount.SubList.ApplyRemoteSub(sub);
|
||||
var account = GetOrCreateAccount(sub.Account);
|
||||
account.SubList.ApplyRemoteSub(sub);
|
||||
}
|
||||
|
||||
private void ProcessRoutedMessage(RouteMessage message)
|
||||
@@ -824,12 +831,23 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
|
||||
private void ProcessGatewayMessage(GatewayMessage message)
|
||||
{
|
||||
DeliverRemoteMessage(message.Subject, message.ReplyTo, message.Payload);
|
||||
var replyTo = message.ReplyTo;
|
||||
if (ReplyMapper.TryRestoreGatewayReply(replyTo, out var restoredReply))
|
||||
replyTo = restoredReply;
|
||||
|
||||
DeliverRemoteMessage(message.Subject, replyTo, message.Payload);
|
||||
}
|
||||
|
||||
private void ProcessLeafMessage(LeafMessage message)
|
||||
{
|
||||
DeliverRemoteMessage(message.Subject, message.ReplyTo, message.Payload);
|
||||
if (LeafLoopDetector.IsLooped(message.Subject, ServerId))
|
||||
return;
|
||||
|
||||
var subject = message.Subject;
|
||||
if (LeafLoopDetector.TryUnmark(subject, out var unmarked))
|
||||
subject = unmarked;
|
||||
|
||||
DeliverRemoteMessage(subject, message.ReplyTo, message.Payload);
|
||||
}
|
||||
|
||||
private void DeliverRemoteMessage(string subject, string? replyTo, ReadOnlyMemory<byte> payload)
|
||||
@@ -883,12 +901,20 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
if (_routeManager != null && _globalAccount.SubList.HasRemoteInterest(subject))
|
||||
var senderAccount = sender.Account ?? _globalAccount;
|
||||
if (_routeManager != null && senderAccount.SubList.HasRemoteInterest(senderAccount.Name, subject))
|
||||
_routeManager.ForwardRoutedMessageAsync(subject, replyTo, payload, default).GetAwaiter().GetResult();
|
||||
if (_gatewayManager != null && _globalAccount.SubList.HasRemoteInterest(subject))
|
||||
_gatewayManager.ForwardMessageAsync(subject, replyTo, payload, default).GetAwaiter().GetResult();
|
||||
if (_leafNodeManager != null && _globalAccount.SubList.HasRemoteInterest(subject))
|
||||
_leafNodeManager.ForwardMessageAsync(subject, replyTo, payload, default).GetAwaiter().GetResult();
|
||||
if (_gatewayManager != null && senderAccount.SubList.HasRemoteInterest(senderAccount.Name, subject))
|
||||
{
|
||||
var mappedReplyTo = ReplyMapper.ToGatewayReply(replyTo, ServerId);
|
||||
_gatewayManager.ForwardMessageAsync(subject, mappedReplyTo, payload, default).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
if (_leafNodeManager != null && senderAccount.SubList.HasRemoteInterest(senderAccount.Name, subject))
|
||||
{
|
||||
var markedSubject = LeafLoopDetector.Mark(subject, ServerId);
|
||||
_leafNodeManager.ForwardMessageAsync(markedSubject, replyTo, payload, default).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
var subList = sender.Account?.SubList ?? _globalAccount.SubList;
|
||||
var result = subList.Match(subject);
|
||||
|
||||
Reference in New Issue
Block a user