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,31 @@
using StellaOps.Router.Common.Models;
namespace StellaOps.Router.Common.Abstractions;
/// <summary>
/// Provides global routing state derived from all live connections.
/// </summary>
public interface IGlobalRoutingState
{
/// <summary>
/// Resolves an HTTP request to an endpoint descriptor.
/// </summary>
/// <param name="method">The HTTP method.</param>
/// <param name="path">The request path.</param>
/// <returns>The endpoint descriptor, or null if not found.</returns>
EndpointDescriptor? ResolveEndpoint(string method, string path);
/// <summary>
/// Gets all connections that can handle the specified endpoint.
/// </summary>
/// <param name="serviceName">The service name.</param>
/// <param name="version">The service version.</param>
/// <param name="method">The HTTP method.</param>
/// <param name="path">The request path.</param>
/// <returns>The available connection states.</returns>
IReadOnlyList<ConnectionState> GetConnectionsFor(
string serviceName,
string version,
string method,
string path);
}

View File

@@ -0,0 +1,17 @@
namespace StellaOps.Router.Common.Abstractions;
/// <summary>
/// Provides region information for routing decisions.
/// </summary>
public interface IRegionProvider
{
/// <summary>
/// Gets the current gateway region.
/// </summary>
string Region { get; }
/// <summary>
/// Gets the neighbor regions in order of preference.
/// </summary>
IReadOnlyList<string> NeighborRegions { get; }
}

View File

@@ -0,0 +1,19 @@
using StellaOps.Router.Common.Models;
namespace StellaOps.Router.Common.Abstractions;
/// <summary>
/// Provides extensibility for routing decisions.
/// </summary>
public interface IRoutingPlugin
{
/// <summary>
/// Chooses an instance for the routing context.
/// </summary>
/// <param name="context">The routing context.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The routing decision, or null if this plugin cannot decide.</returns>
Task<RoutingDecision?> ChooseInstanceAsync(
RoutingContext context,
CancellationToken cancellationToken);
}

View File

@@ -0,0 +1,51 @@
using StellaOps.Router.Common.Models;
namespace StellaOps.Router.Common.Abstractions;
/// <summary>
/// Represents a transport client for sending requests to microservices.
/// </summary>
public interface ITransportClient
{
/// <summary>
/// Sends a request and waits for a response.
/// </summary>
/// <param name="connection">The connection to use.</param>
/// <param name="requestFrame">The request frame.</param>
/// <param name="timeout">The timeout for the request.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The response frame.</returns>
Task<Frame> SendRequestAsync(
ConnectionState connection,
Frame requestFrame,
TimeSpan timeout,
CancellationToken cancellationToken);
/// <summary>
/// Sends a cancellation request.
/// </summary>
/// <param name="connection">The connection to use.</param>
/// <param name="correlationId">The correlation ID of the request to cancel.</param>
/// <param name="reason">Optional reason for cancellation.</param>
Task SendCancelAsync(
ConnectionState connection,
Guid correlationId,
string? reason = null);
/// <summary>
/// Sends a streaming request and processes the streaming response.
/// </summary>
/// <param name="connection">The connection to use.</param>
/// <param name="requestHeader">The request header frame.</param>
/// <param name="requestBody">The request body stream.</param>
/// <param name="readResponseBody">Callback to read the response body stream.</param>
/// <param name="limits">Payload limits to enforce.</param>
/// <param name="cancellationToken">Cancellation token.</param>
Task SendStreamingAsync(
ConnectionState connection,
Frame requestHeader,
Stream requestBody,
Func<Stream, Task> readResponseBody,
PayloadLimits limits,
CancellationToken cancellationToken);
}

View File

@@ -0,0 +1,19 @@
namespace StellaOps.Router.Common.Abstractions;
/// <summary>
/// Represents a transport server that accepts connections from microservices.
/// </summary>
public interface ITransportServer
{
/// <summary>
/// Starts listening for incoming connections.
/// </summary>
/// <param name="cancellationToken">Cancellation token.</param>
Task StartAsync(CancellationToken cancellationToken);
/// <summary>
/// Stops accepting new connections.
/// </summary>
/// <param name="cancellationToken">Cancellation token.</param>
Task StopAsync(CancellationToken cancellationToken);
}