StellaOps.Router.Transport.InMemory
Router in-memory transport: connects microservices and a gateway inside one process, for development and tests. Install Installing Stella Ops packagesRouter downloads and signaturesnet10.01.0.1-20261117T070237Zdotnet add package StellaOps.
Namespaces
| Namespace | Types |
|---|---|
StellaOps. | 7 |
namespace StellaOps.Router.Transport.InMemory
| Type | Kind | Description |
|---|---|---|
InMemoryChannel | class | Represents a bidirectional in-memory channel for frame passing between gateway and microservice. |
InMemoryConnectionRegistry | class | Thread-safe registry for in-memory connections. |
InMemoryTransportClient | class | In-memory transport client implementation for testing and development. |
InMemoryTransportOptions | class | Configuration options for the InMemory transport. |
InMemoryTransportPlugin | class | Plugin implementation for InMemory transport (for testing and development). |
InMemoryTransportServer | class | In-memory transport server implementation for testing and development. |
InMemoryTransportServiceCollectionExtensions | class | Extension methods for registering InMemory transport services. |
class InMemoryChannel
public sealed class InMemoryChannel : IDisposable
Represents a bidirectional in-memory channel for frame passing between gateway and microservice.
Members
| Member | Kind | Summary |
|---|---|---|
InMemoryChannel( | constructor | Initializes a new instance of the InMemoryChannelclass. |
ConnectionId | property | Gets the connection ID. |
Instance | property | Gets or sets the instance descriptor for this connection. |
LifetimeToken | property | Gets the cancellation token source for this connection’s lifetime. |
State | property | Gets or sets the connection state. |
ToGateway | property | Gets the channel for frames from microservice to gateway. |
ToMicroservice | property | Gets the channel for frames from gateway to microservice. |
Dispose( | method | Disposes the channel and cancels all pending operations. |
constructor InMemoryChannel(string, int) #
InMemoryChannel(string, int) #public InMemoryChannel(string connectionId, int bufferSize = 0)
Initializes a new instance of the InMemoryChannelclass.
Parameters
connectionId: The connection ID.bufferSize: The channel buffer size. Zero for unbounded.
property ConnectionId #
ConnectionId #public string ConnectionId { get; }
Gets the connection ID.
property Instance #
Instance #public InstanceDescriptor? Instance { get; set; }
Gets or sets the instance descriptor for this connection. Set when HELLO is processed.
property LifetimeToken #
LifetimeToken #public CancellationTokenSource LifetimeToken { get; }
Gets the cancellation token source for this connection’s lifetime.
property State #
State #public ConnectionState? State { get; set; }
Gets or sets the connection state.
property ToGateway #
ToGateway #public Channel<Frame> ToGateway { get; }
Gets the channel for frames from microservice to gateway. SDK writes, Gateway reads.
property ToMicroservice #
ToMicroservice #public Channel<Frame> ToMicroservice { get; }
Gets the channel for frames from gateway to microservice. Gateway writes, SDK reads.
method Dispose() #
Dispose() #public void Dispose()
Disposes the channel and cancels all pending operations.
class InMemoryConnectionRegistry
public sealed class InMemoryConnectionRegistry : IDisposable
Thread-safe registry for in-memory connections.
Members
| Member | Kind | Summary |
|---|---|---|
InMemoryConnectionRegistry( | constructor | Creates an instance of In. |
ConnectionIds | property | Gets all connection IDs. |
Count | property | Gets the count of active connections. |
CreateChannel( | method | Creates a new channel with the given connection ID. |
Dispose( | method | Disposes all channels. |
GetAllConnections( | method | Gets all active connection states. |
GetChannel( | method | Gets a channel by connection ID. |
GetConnectionsFor( | method | Gets connections for a specific service and endpoint. |
GetRequiredChannel( | method | Gets a channel by connection ID, throwing if not found. |
RemoveChannel( | method | Removes and disposes a channel by connection ID. |
constructor InMemoryConnectionRegistry() #
InMemoryConnectionRegistry() #public InMemoryConnectionRegistry()
Creates an instance of In.
property ConnectionIds #
ConnectionIds #public IEnumerable<string> ConnectionIds { get; }
Gets all connection IDs.
property Count #
Count #public int Count { get; }
Gets the count of active connections.
method CreateChannel(string, int) #
CreateChannel(string, int) #public InMemoryChannel CreateChannel(string connectionId, int bufferSize = 0)
Creates a new channel with the given connection ID.
Parameters
connectionId: The connection ID.bufferSize: The channel buffer size.
Returns
The created channel.
method Dispose() #
Dispose() #public void Dispose()
Disposes all channels.
method GetAllConnections() #
GetAllConnections() #public IReadOnlyList<ConnectionState> GetAllConnections()
Gets all active connection states.
method GetChannel(string) #
GetChannel(string) #public InMemoryChannel? GetChannel(string connectionId)
Gets a channel by connection ID.
Parameters
connectionId: The connection ID.
Returns
The channel, or null if not found.
method GetConnectionsFor(string, string, string, string) #
GetConnectionsFor(string, string, string, string) #public IReadOnlyList<ConnectionState> GetConnectionsFor(string serviceName, string version, string method, string path)
Gets connections for a specific service and endpoint.
Parameters
serviceName: The service name.version: The version.method: The HTTP method.path: The path.
method GetRequiredChannel(string) #
GetRequiredChannel(string) #public InMemoryChannel GetRequiredChannel(string connectionId)
Gets a channel by connection ID, throwing if not found.
Parameters
connectionId: The connection ID.
Returns
The channel.
method RemoveChannel(string) #
RemoveChannel(string) #public bool RemoveChannel(string connectionId)
Removes and disposes a channel by connection ID.
Parameters
connectionId: The connection ID.
Returns
True if the channel was found and removed.
class InMemoryTransportClient
public sealed class InMemoryTransportClient : ITransportClient, IMicroserviceTransport, IDisposable
In-memory transport client implementation for testing and development. Used by the Microservice SDK to send frames to the Gateway.
Members
constructor InMemoryTransportClient(InMemoryConnectionRegistry, IOptions<InMemoryTransportOptions>, ILogger<InMemoryTransportClient>, InMemoryTransportServer) #
InMemoryTransportClient(InMemoryConnectionRegistry, IOptions<InMemoryTransportOptions>, ILogger<InMemoryTransportClient>, InMemoryTransportServer) #public InMemoryTransportClient(InMemoryConnectionRegistry registry, IOptions<InMemoryTransportOptions> options, ILogger<InMemoryTransportClient> logger, InMemoryTransportServer? transportServer = null)
Initializes a new instance of the InMemoryTransportClientclass.
event OnCancelReceived #
OnCancelReceived #public event Func<Guid, string?, Task>? OnCancelReceived
Event raised when a CANCEL frame is received from the gateway.
event OnRequestReceived #
OnRequestReceived #public event Func<Frame, CancellationToken, Task<Frame>>? OnRequestReceived
Event raised when a REQUEST frame is received from the gateway.
method CancelAllInflight(string) #
CancelAllInflight(string) #public void CancelAllInflight(string reason)
Cancels all in-flight handler requests. Called when connection is closed or transport is shutting down.
Parameters
reason: The reason for cancellation.
method ConnectAsync(InstanceDescriptor, IReadOnlyList<EndpointDescriptor>, CancellationToken) #
ConnectAsync(InstanceDescriptor, IReadOnlyList<EndpointDescriptor>, CancellationToken) #public Task ConnectAsync(InstanceDescriptor instance, IReadOnlyList<EndpointDescriptor> endpoints, CancellationToken cancellationToken)
Connects to the in-memory transport and sends a HELLO frame without schemas or OpenAPI metadata.
Parameters
instance: The instance descriptor.endpoints: The endpoints to register.cancellationToken: Cancellation token.
method ConnectAsync(InstanceDescriptor, IReadOnlyList<EndpointDescriptor>, IReadOnlyDictionary<string, SchemaDefinition>, ServiceOpenApiInfo, CancellationToken) #
ConnectAsync(InstanceDescriptor, IReadOnlyList<EndpointDescriptor>, IReadOnlyDictionary<string, SchemaDefinition>, ServiceOpenApiInfo, CancellationToken) #public Task ConnectAsync(InstanceDescriptor instance, IReadOnlyList<EndpointDescriptor> endpoints, IReadOnlyDictionary<string, SchemaDefinition>? schemas, ServiceOpenApiInfo? openApiInfo, CancellationToken cancellationToken)
Connects to the in-memory transport and sends a HELLO frame. The gateway reads the endpoints, the schema definitions they reference and the OpenAPI metadata from the connection state this method registers.
Parameters
instance: The instance descriptor.endpoints: The endpoints to register.schemas: Schema definitions referenced by the endpoints, ornull.openApiInfo: OpenAPI metadata for the service, ornull.cancellationToken: Cancellation token.
method DisconnectAsync() #
DisconnectAsync() #public Task DisconnectAsync()
Disconnects from the transport.
method Dispose() #
Dispose() #public void Dispose()
See IDisposable..
method SendCancelAsync(ConnectionState, Guid, string) #
SendCancelAsync(ConnectionState, Guid, string) #public Task SendCancelAsync(ConnectionState connection, Guid correlationId, string? reason = null)
Sends a cancellation request.
Parameters
connection: The connection to use.correlationId: The correlation ID of the request to cancel.reason: Optional reason for cancellation.
method SendGoodbyeAsync(CancellationToken) #
SendGoodbyeAsync(CancellationToken) #public Task SendGoodbyeAsync(CancellationToken cancellationToken)
Sends a best-effort Goodbye control frame before shutdown. Transports that do not maintain a live microservice connection may no-op.
Parameters
cancellationToken: Cancellation token.
method SendHeartbeatAsync(HeartbeatPayload, CancellationToken) #
SendHeartbeatAsync(HeartbeatPayload, CancellationToken) #public Task SendHeartbeatAsync(HeartbeatPayload heartbeat, CancellationToken cancellationToken)
Sends a heartbeat frame.
method SendRequestAsync(ConnectionState, Frame, TimeSpan, CancellationToken) #
SendRequestAsync(ConnectionState, Frame, TimeSpan, CancellationToken) #public Task<Frame> SendRequestAsync(ConnectionState connection, Frame requestFrame, TimeSpan timeout, CancellationToken cancellationToken)
Sends a request and waits for a response.
Parameters
connection: The connection to use.requestFrame: The request frame.timeout: The timeout for the request.cancellationToken: Cancellation token.
Returns
The response frame.
method SendStreamingAsync(ConnectionState, Frame, Stream, Func<ResponseFrame, Stream, Task>, PayloadLimits, CancellationToken) #
SendStreamingAsync(ConnectionState, Frame, Stream, Func<ResponseFrame, Stream, Task>, PayloadLimits, CancellationToken) #public Task SendStreamingAsync(ConnectionState connection, Frame requestHeader, Stream requestBody, Func<ResponseFrame, Stream, Task> readResponse, PayloadLimits limits, CancellationToken cancellationToken)
Sends a request whose body is read from a stream and hands the microservice’s response to readResponse. TransportStreamingDispatch.implements it for transports whose microservice side answers a request with one response frame.
Parameters
connection: The connection to use.requestHeader: The request header frame.requestBody: The request body stream.readResponse: Callback that receives the response head (the status code and headers of the microservice’s response; itsResponseFrame.is empty) and the response body stream.Payload limits: Payload limits to enforce.cancellationToken: Cancellation token.
Remarks
The request body is read into one request frame (TransportStreamingDispatch.): the in-memory channel carries whole frames and the SDK answers with one response frame.
class InMemoryTransportOptions
public sealed class InMemoryTransportOptions
Configuration options for the InMemory transport.
Members
| Member | Kind | Summary |
|---|---|---|
InMemoryTransportOptions( | constructor | Creates an instance of In. |
ChannelBufferSize | property | Gets or sets the channel buffer size. |
DefaultTimeout | property | Gets or sets the default timeout for requests. |
HeartbeatInterval | property | Gets or sets the heartbeat interval. |
HeartbeatTimeout | property | Gets or sets the heartbeat timeout (time since last heartbeat before connection is considered unhealthy). |
SimulatedLatency | property | Gets or sets the simulated latency for frame delivery. |
constructor InMemoryTransportOptions() #
InMemoryTransportOptions() #public InMemoryTransportOptions()
Creates an instance of In.
property ChannelBufferSize #
ChannelBufferSize #public int ChannelBufferSize { get; set; }
Gets or sets the channel buffer size. Default: Unbounded (0 means unbounded).
property DefaultTimeout #
DefaultTimeout #public TimeSpan DefaultTimeout { get; set; }
Gets or sets the default timeout for requests. Default: 30 seconds.
property HeartbeatInterval #
HeartbeatInterval #public TimeSpan HeartbeatInterval { get; set; }
Gets or sets the heartbeat interval. Default: 45 seconds.
property HeartbeatTimeout #
HeartbeatTimeout #public TimeSpan HeartbeatTimeout { get; set; }
Gets or sets the heartbeat timeout (time since last heartbeat before connection is considered unhealthy). Default: 135 seconds (3x heartbeat interval).
property SimulatedLatency #
SimulatedLatency #public TimeSpan SimulatedLatency { get; set; }
Gets or sets the simulated latency for frame delivery. Default: Zero (instant delivery).
class InMemoryTransportPlugin
public sealed class InMemoryTransportPlugin : IRouterTransportPlugin
Plugin implementation for InMemory transport (for testing and development). The in-process channel has no network server, so one plugin provides both sides.
Members
| Member | Kind | Summary |
|---|---|---|
InMemoryTransportPlugin( | constructor | Creates an instance of In. |
DisplayName | property | Gets the human-readable display name for this transport. |
Mode | property | Gets the side of the transport this plugin registers: RouterTransportMode., RouterTransportMode., or RouterTransportMode.. |
TransportName | property | Gets the transport name (e.g., “tcp”, “tls”, “udp”, “rabbitmq”, “inmemory”, “messaging”), shared by the client and the server plugin of one transport. |
Register( | method | Registers transport services into the DI container for the side the context asks for. |
constructor InMemoryTransportPlugin() #
InMemoryTransportPlugin() #public InMemoryTransportPlugin()
Creates an instance of In.
property DisplayName #
DisplayName #public string DisplayName { get; }
Gets the human-readable display name for this transport.
property Mode #
Mode #public RouterTransportMode Mode { get; }
Gets the side of the transport this plugin registers: RouterTransportMode., RouterTransportMode., or RouterTransportMode.. IRouterTransportPlugin.refuses a context that asks for a side outside this value (RouterTransportRegistrationContext.).
property TransportName #
TransportName #public string TransportName { get; }
Gets the transport name (e.g., “tcp”, “tls”, “udp”, “rabbitmq”, “inmemory”, “messaging”), shared by the client and the server plugin of one transport.
method Register(RouterTransportRegistrationContext) #
Register(RouterTransportRegistrationContext) #public void Register(RouterTransportRegistrationContext context)
Registers transport services into the DI container for the side the context asks for.
Parameters
context: The registration context containing services, configuration, and transport mode.
Exceptions
Invalid: The context asks for a side this plugin does not provide.Operation Exception
class InMemoryTransportServer
public sealed class InMemoryTransportServer : ITransportServer, IDisposable
In-memory transport server implementation for testing and development. Used by the Gateway to receive frames from microservices.
Members
| Member | Kind | Summary |
|---|---|---|
InMemoryTransportServer( | constructor | Initializes a new instance of the InMemoryTransportServerclass. |
OnConnectionClosed | event | Event raised when a connection is closed. |
OnHeartbeatReceived | event | Event raised when a HEARTBEAT frame is received. |
OnHelloReceived | event | Event raised when a HELLO frame is received. |
OnResponseReceived | event | Event raised when a RESPONSE frame is received. |
Dispose( | method | See IDisposable.. |
SendToMicroserviceAsync( | method | Sends a frame to a microservice via the ToMicroservice channel. |
StartAsync( | method | Starts listening for incoming connections. |
StartListeningToConnection( | method | Starts listening to a specific connection’s ToGateway channel. |
StopAsync( | method | Stops accepting new connections. |
constructor InMemoryTransportServer(InMemoryConnectionRegistry, IOptions<InMemoryTransportOptions>, ILogger<InMemoryTransportServer>) #
InMemoryTransportServer(InMemoryConnectionRegistry, IOptions<InMemoryTransportOptions>, ILogger<InMemoryTransportServer>) #public InMemoryTransportServer(InMemoryConnectionRegistry registry, IOptions<InMemoryTransportOptions> options, ILogger<InMemoryTransportServer> logger)
Initializes a new instance of the InMemoryTransportServerclass.
event OnConnectionClosed #
OnConnectionClosed #public event Func<string, Task>? OnConnectionClosed
Event raised when a connection is closed.
event OnHeartbeatReceived #
OnHeartbeatReceived #public event Func<ConnectionState, HeartbeatPayload, Task>? OnHeartbeatReceived
Event raised when a HEARTBEAT frame is received.
event OnHelloReceived #
OnHelloReceived #public event Func<ConnectionState, HelloPayload, Task>? OnHelloReceived
Event raised when a HELLO frame is received.
event OnResponseReceived #
OnResponseReceived #public event Func<ConnectionState, Frame, Task>? OnResponseReceived
Event raised when a RESPONSE frame is received.
method Dispose() #
Dispose() #public void Dispose()
See IDisposable..
method SendToMicroserviceAsync(string, Frame, CancellationToken) #
SendToMicroserviceAsync(string, Frame, CancellationToken) #public ValueTask SendToMicroserviceAsync(string connectionId, Frame frame, CancellationToken cancellationToken)
Sends a frame to a microservice via the ToMicroservice channel.
method StartAsync(CancellationToken) #
StartAsync(CancellationToken) #public Task StartAsync(CancellationToken cancellationToken)
Starts listening for incoming connections.
Parameters
cancellationToken: Cancellation token.
method StartListeningToConnection(string) #
StartListeningToConnection(string) #public void StartListeningToConnection(string connectionId)
Starts listening to a specific connection’s ToGateway channel. Called when a new connection is registered.
method StopAsync(CancellationToken) #
StopAsync(CancellationToken) #public Task StopAsync(CancellationToken cancellationToken)
Stops accepting new connections.
Parameters
cancellationToken: Cancellation token.
class InMemoryTransportServiceCollectionExtensions
public static class InMemoryTransportServiceCollectionExtensions
Extension methods for registering InMemory transport services.
Members
| Member | Kind | Summary |
|---|---|---|
AddInMemoryTransport( | extension method | Adds the InMemory transport for testing and development. |
AddInMemoryTransportClient( | extension method | Adds the InMemory transport client only (for Microservice SDK). |
AddInMemoryTransportServer( | extension method | Adds the InMemory transport server only (for Gateway). |
extension method AddInMemoryTransport(IServiceCollection, Action<InMemoryTransportOptions>) #
AddInMemoryTransport(IServiceCollection, Action<InMemoryTransportOptions>) #public static IServiceCollection AddInMemoryTransport(this IServiceCollection services, Action<InMemoryTransportOptions>? configure = null)
Adds the InMemory transport for testing and development.
Parameters
services: The service collection.configure: Optional configuration action.
Returns
The service collection for chaining.
extension method AddInMemoryTransportClient(IServiceCollection, Action<InMemoryTransportOptions>) #
AddInMemoryTransportClient(IServiceCollection, Action<InMemoryTransportOptions>) #public static IServiceCollection AddInMemoryTransportClient(this IServiceCollection services, Action<InMemoryTransportOptions>? configure = null)
Adds the InMemory transport client only (for Microservice SDK).
Parameters
services: The service collection.configure: Optional configuration action.
Returns
The service collection for chaining.
extension method AddInMemoryTransportServer(IServiceCollection, Action<InMemoryTransportOptions>) #
AddInMemoryTransportServer(IServiceCollection, Action<InMemoryTransportOptions>) #public static IServiceCollection AddInMemoryTransportServer(this IServiceCollection services, Action<InMemoryTransportOptions>? configure = null)
Adds the InMemory transport server only (for Gateway).
Parameters
services: The service collection.configure: Optional configuration action.
Returns
The service collection for chaining.