feat: add jetstream api router and error envelope
This commit is contained in:
7
src/NATS.Server/JetStream/Api/JetStreamApiError.cs
Normal file
7
src/NATS.Server/JetStream/Api/JetStreamApiError.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace NATS.Server.JetStream.Api;
|
||||
|
||||
public sealed class JetStreamApiError
|
||||
{
|
||||
public int Code { get; init; }
|
||||
public string Description { get; init; } = string.Empty;
|
||||
}
|
||||
46
src/NATS.Server/JetStream/Api/JetStreamApiResponse.cs
Normal file
46
src/NATS.Server/JetStream/Api/JetStreamApiResponse.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
namespace NATS.Server.JetStream.Api;
|
||||
|
||||
public sealed class JetStreamApiResponse
|
||||
{
|
||||
public JetStreamApiError? Error { get; init; }
|
||||
public JetStreamStreamInfo? StreamInfo { get; init; }
|
||||
public JetStreamConsumerInfo? ConsumerInfo { get; init; }
|
||||
|
||||
public static JetStreamApiResponse NotFound(string subject) => new()
|
||||
{
|
||||
Error = new JetStreamApiError
|
||||
{
|
||||
Code = 404,
|
||||
Description = $"unknown api subject '{subject}'",
|
||||
},
|
||||
};
|
||||
|
||||
public static JetStreamApiResponse Ok() => new();
|
||||
}
|
||||
|
||||
public sealed class JetStreamStreamInfo
|
||||
{
|
||||
public required JetStreamStreamConfig Config { get; init; }
|
||||
public required JetStreamStreamState State { get; init; }
|
||||
}
|
||||
|
||||
public sealed class JetStreamConsumerInfo
|
||||
{
|
||||
public required JetStreamConsumerConfig Config { get; init; }
|
||||
}
|
||||
|
||||
public sealed class JetStreamStreamConfig
|
||||
{
|
||||
public string Name { get; init; } = string.Empty;
|
||||
}
|
||||
|
||||
public sealed class JetStreamStreamState
|
||||
{
|
||||
public ulong Messages { get; init; }
|
||||
public ulong FirstSeq { get; init; }
|
||||
}
|
||||
|
||||
public sealed class JetStreamConsumerConfig
|
||||
{
|
||||
public string DurableName { get; init; } = string.Empty;
|
||||
}
|
||||
7
src/NATS.Server/JetStream/Api/JetStreamApiRouter.cs
Normal file
7
src/NATS.Server/JetStream/Api/JetStreamApiRouter.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace NATS.Server.JetStream.Api;
|
||||
|
||||
public sealed class JetStreamApiRouter
|
||||
{
|
||||
public JetStreamApiResponse Route(string subject, ReadOnlySpan<byte> payload)
|
||||
=> JetStreamApiResponse.NotFound(subject);
|
||||
}
|
||||
@@ -11,6 +11,7 @@ using NATS.Server.Auth;
|
||||
using NATS.Server.Configuration;
|
||||
using NATS.Server.Gateways;
|
||||
using NATS.Server.JetStream;
|
||||
using NATS.Server.JetStream.Api;
|
||||
using NATS.Server.LeafNodes;
|
||||
using NATS.Server.Monitoring;
|
||||
using NATS.Server.Protocol;
|
||||
@@ -47,6 +48,7 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
private readonly GatewayManager? _gatewayManager;
|
||||
private readonly LeafNodeManager? _leafNodeManager;
|
||||
private readonly JetStreamService? _jetStreamService;
|
||||
private readonly JetStreamApiRouter? _jetStreamApiRouter;
|
||||
private Socket? _listener;
|
||||
private Socket? _wsListener;
|
||||
private readonly TaskCompletionSource _wsAcceptLoopExited = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
@@ -84,6 +86,7 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
public bool IsShuttingDown => Volatile.Read(ref _shutdown) != 0;
|
||||
public bool IsLameDuckMode => Volatile.Read(ref _lameDuck) != 0;
|
||||
public string? ClusterListen => _routeManager?.ListenEndpoint;
|
||||
public JetStreamApiRouter? JetStreamApiRouter => _jetStreamApiRouter;
|
||||
public Action? ReOpenLogFile { get; set; }
|
||||
public IEnumerable<NatsClient> GetClients() => _clients.Values;
|
||||
|
||||
@@ -327,6 +330,7 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
|
||||
if (options.JetStream != null)
|
||||
{
|
||||
_jetStreamService = new JetStreamService(options.JetStream);
|
||||
_jetStreamApiRouter = new JetStreamApiRouter();
|
||||
}
|
||||
|
||||
if (options.HasTls)
|
||||
|
||||
Reference in New Issue
Block a user