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,87 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using StellaOps.Router.Common.Abstractions;
namespace StellaOps.Router.Transport.InMemory;
/// <summary>
/// Extension methods for registering InMemory transport services.
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds the InMemory transport for testing and development.
/// </summary>
/// <param name="services">The service collection.</param>
/// <param name="configure">Optional configuration action.</param>
/// <returns>The service collection for chaining.</returns>
public static IServiceCollection AddInMemoryTransport(
this IServiceCollection services,
Action<InMemoryTransportOptions>? configure = null)
{
services.AddOptions<InMemoryTransportOptions>();
if (configure is not null)
{
services.Configure(configure);
}
// Singleton registry shared between server and client
services.TryAddSingleton<InMemoryConnectionRegistry>();
// Transport implementations
services.TryAddSingleton<InMemoryTransportServer>();
services.TryAddSingleton<InMemoryTransportClient>();
// Register interfaces
services.TryAddSingleton<ITransportServer>(sp => sp.GetRequiredService<InMemoryTransportServer>());
services.TryAddSingleton<ITransportClient>(sp => sp.GetRequiredService<InMemoryTransportClient>());
return services;
}
/// <summary>
/// Adds the InMemory transport server only (for Gateway).
/// </summary>
/// <param name="services">The service collection.</param>
/// <param name="configure">Optional configuration action.</param>
/// <returns>The service collection for chaining.</returns>
public static IServiceCollection AddInMemoryTransportServer(
this IServiceCollection services,
Action<InMemoryTransportOptions>? configure = null)
{
services.AddOptions<InMemoryTransportOptions>();
if (configure is not null)
{
services.Configure(configure);
}
services.TryAddSingleton<InMemoryConnectionRegistry>();
services.TryAddSingleton<InMemoryTransportServer>();
services.TryAddSingleton<ITransportServer>(sp => sp.GetRequiredService<InMemoryTransportServer>());
return services;
}
/// <summary>
/// Adds the InMemory transport client only (for Microservice SDK).
/// </summary>
/// <param name="services">The service collection.</param>
/// <param name="configure">Optional configuration action.</param>
/// <returns>The service collection for chaining.</returns>
public static IServiceCollection AddInMemoryTransportClient(
this IServiceCollection services,
Action<InMemoryTransportOptions>? configure = null)
{
services.AddOptions<InMemoryTransportOptions>();
if (configure is not null)
{
services.Configure(configure);
}
services.TryAddSingleton<InMemoryConnectionRegistry>();
services.TryAddSingleton<InMemoryTransportClient>();
services.TryAddSingleton<ITransportClient>(sp => sp.GetRequiredService<InMemoryTransportClient>());
return services;
}
}