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:
StellaOps Bot
2025-12-05 01:00:10 +02:00
parent 8768c27f30
commit 175b750e29
111 changed files with 25407 additions and 19242 deletions

View File

@@ -0,0 +1,71 @@
using System.Reflection;
using StellaOps.Router.Common.Models;
namespace StellaOps.Microservice;
/// <summary>
/// Discovers endpoints using runtime reflection.
/// </summary>
public sealed class ReflectionEndpointDiscoveryProvider : IEndpointDiscoveryProvider
{
private readonly StellaMicroserviceOptions _options;
private readonly IEnumerable<Assembly> _assemblies;
/// <summary>
/// Initializes a new instance of the <see cref="ReflectionEndpointDiscoveryProvider"/> class.
/// </summary>
/// <param name="options">The microservice options.</param>
/// <param name="assemblies">The assemblies to scan for endpoints.</param>
public ReflectionEndpointDiscoveryProvider(StellaMicroserviceOptions options, IEnumerable<Assembly>? assemblies = null)
{
_options = options;
_assemblies = assemblies ?? AppDomain.CurrentDomain.GetAssemblies();
}
/// <inheritdoc />
public IReadOnlyList<EndpointDescriptor> DiscoverEndpoints()
{
var endpoints = new List<EndpointDescriptor>();
foreach (var assembly in _assemblies)
{
try
{
foreach (var type in assembly.GetTypes())
{
var attribute = type.GetCustomAttribute<StellaEndpointAttribute>();
if (attribute is null) continue;
if (!typeof(IStellaEndpoint).IsAssignableFrom(type))
{
throw new InvalidOperationException(
$"Type {type.FullName} has [StellaEndpoint] but does not implement IStellaEndpoint.");
}
var claims = attribute.RequiredClaims
.Select(c => new ClaimRequirement { Type = c })
.ToList();
var descriptor = new EndpointDescriptor
{
ServiceName = _options.ServiceName,
Version = _options.Version,
Method = attribute.Method,
Path = attribute.Path,
DefaultTimeout = TimeSpan.FromSeconds(attribute.TimeoutSeconds),
SupportsStreaming = attribute.SupportsStreaming,
RequiringClaims = claims
};
endpoints.Add(descriptor);
}
}
catch (ReflectionTypeLoadException)
{
// Skip assemblies that cannot be loaded
}
}
return endpoints;
}
}