feat(batch27): implement jetstream bootstrap and account wiring

This commit is contained in:
Joseph Doherty
2026-02-28 20:57:02 -05:00
parent 0ad3d08777
commit 4b7fac7957
7 changed files with 501 additions and 11 deletions

View File

@@ -0,0 +1,62 @@
namespace ZB.MOM.NatsNet.Server;
public sealed partial class Account
{
internal Exception? EnableAllJetStreamServiceImportsAndMappings()
{
_mu.EnterReadLock();
var server = Server as NatsServer;
_mu.ExitReadLock();
if (server == null)
return new InvalidOperationException("jetstream account not registered");
var systemAccount = server.SystemAccount();
var destinationName = systemAccount?.Name ?? string.Empty;
if (systemAccount != null && !ServiceImportExists(destinationName, JsApiSubjects.JsAllApi))
{
var err = AddServiceImport(systemAccount, JsApiSubjects.JsAllApi, JsApiSubjects.JsAllApi);
if (err != null)
return new InvalidOperationException($"error setting up jetstream service imports for account: {err.Message}", err);
}
var domain = server.GetOpts().JetStreamDomain;
if (!string.IsNullOrWhiteSpace(domain))
{
var mappings = new Dictionary<string, string>(StringComparer.Ordinal)
{
[$"$JS.{domain}.API.>"] = JsApiSubjects.JsAllApi,
[$"$JS.{domain}.API.INFO"] = JsApiSubjects.JsApiAccountInfo,
};
_mu.EnterReadLock();
try
{
foreach (var mapping in _mappings)
mappings.Remove(mapping.Source);
}
finally
{
_mu.ExitReadLock();
}
foreach (var (src, dest) in mappings)
{
var err = AddMapping(src, dest);
if (err != null)
server.Errorf("Error adding JetStream domain mapping: {0}", err.Message);
}
}
return null;
}
internal Exception? EnableJetStreamInfoServiceImportOnly()
{
if (ServiceImportShadowed(JsApiSubjects.JsApiAccountInfo))
return null;
return EnableAllJetStreamServiceImportsAndMappings();
}
}