feat(batch27): implement jetstream bootstrap and account wiring
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user