feat: add reload semantics for cluster and jetstream options
This commit is contained in:
@@ -1025,10 +1025,22 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
/// the changes, and applies reloadable settings. CLI overrides are preserved.
|
||||
/// </summary>
|
||||
public void ReloadConfig()
|
||||
{
|
||||
ReloadConfigCore(throwOnError: false);
|
||||
}
|
||||
|
||||
public void ReloadConfigOrThrow()
|
||||
{
|
||||
ReloadConfigCore(throwOnError: true);
|
||||
}
|
||||
|
||||
private void ReloadConfigCore(bool throwOnError)
|
||||
{
|
||||
if (_options.ConfigFile == null)
|
||||
{
|
||||
_logger.LogWarning("No config file specified, cannot reload");
|
||||
if (throwOnError)
|
||||
throw new InvalidOperationException("No config file specified.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1054,6 +1066,8 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
{
|
||||
foreach (var err in errors)
|
||||
_logger.LogError("Config reload error: {Error}", err);
|
||||
if (throwOnError)
|
||||
throw new InvalidOperationException(string.Join("; ", errors));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1065,6 +1079,8 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to reload config file: {ConfigFile}", _options.ConfigFile);
|
||||
if (throwOnError)
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user