Implement InMemory Transport Layer for StellaOps Router
- Added InMemoryTransportOptions class for configuration settings including timeouts and latency. - Developed InMemoryTransportServer class to handle connections, frame processing, and event management. - Created ServiceCollectionExtensions for easy registration of InMemory transport services. - Established project structure and dependencies for InMemory transport library. - Implemented comprehensive unit tests for endpoint discovery, connection management, request/response flow, and streaming capabilities. - Ensured proper handling of cancellation, heartbeat, and hello frames within the transport layer.
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
using StellaOps.Router.Common;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace StellaOps.Microservice;
|
||||
|
||||
/// <summary>
|
||||
/// Options for configuring a Stella microservice.
|
||||
/// </summary>
|
||||
public sealed class StellaMicroserviceOptions
|
||||
public sealed partial class StellaMicroserviceOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the service name.
|
||||
@@ -14,6 +14,7 @@ public sealed class StellaMicroserviceOptions
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the semantic version.
|
||||
/// Must be valid semver (e.g., "1.0.0", "2.1.0-beta.1").
|
||||
/// </summary>
|
||||
public required string Version { get; set; }
|
||||
|
||||
@@ -24,6 +25,7 @@ public sealed class StellaMicroserviceOptions
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the unique instance identifier.
|
||||
/// Auto-generated if not provided.
|
||||
/// </summary>
|
||||
public string InstanceId { get; set; } = Guid.NewGuid().ToString("N");
|
||||
|
||||
@@ -36,5 +38,55 @@ public sealed class StellaMicroserviceOptions
|
||||
/// <summary>
|
||||
/// Gets or sets the optional path to a YAML config file for endpoint overrides.
|
||||
/// </summary>
|
||||
public string? EndpointConfigPath { get; set; }
|
||||
public string? ConfigFilePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the heartbeat interval.
|
||||
/// Default: 10 seconds.
|
||||
/// </summary>
|
||||
public TimeSpan HeartbeatInterval { get; set; } = TimeSpan.FromSeconds(10);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum reconnect backoff.
|
||||
/// Default: 1 minute.
|
||||
/// </summary>
|
||||
public TimeSpan ReconnectBackoffMax { get; set; } = TimeSpan.FromMinutes(1);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the initial reconnect delay.
|
||||
/// Default: 1 second.
|
||||
/// </summary>
|
||||
public TimeSpan ReconnectBackoffInitial { get; set; } = TimeSpan.FromSeconds(1);
|
||||
|
||||
/// <summary>
|
||||
/// Validates the options and throws if invalid.
|
||||
/// </summary>
|
||||
public void Validate()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ServiceName))
|
||||
throw new InvalidOperationException("ServiceName is required.");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Version))
|
||||
throw new InvalidOperationException("Version is required.");
|
||||
|
||||
if (!SemverRegex().IsMatch(Version))
|
||||
throw new InvalidOperationException($"Version '{Version}' is not valid semver.");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Region))
|
||||
throw new InvalidOperationException("Region is required.");
|
||||
|
||||
if (Routers.Count == 0)
|
||||
throw new InvalidOperationException("At least one router endpoint is required.");
|
||||
|
||||
foreach (var router in Routers)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(router.Host))
|
||||
throw new InvalidOperationException("Router host is required.");
|
||||
if (router.Port <= 0 || router.Port > 65535)
|
||||
throw new InvalidOperationException($"Router port {router.Port} is invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$")]
|
||||
private static partial Regex SemverRegex();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user