StellaOps.Router.Transport.Udp
Router UDP transport, client side: sends the frames of a microservice to a gateway as UDP datagrams. Install Installing Stella Ops packagesRouter downloads and signaturesnet10.01.0.1-20261117T070237Zdotnet add package StellaOps.
Namespaces
| Namespace | Types |
|---|---|
StellaOps. | 5 |
namespace StellaOps.Router.Transport.Udp
| Type | Kind | Description |
|---|---|---|
UdpFrameProtocol | class | Handles serialization and deserialization of frames for UDP transport. |
UdpTransportClient | class | UDP transport client implementation for microservices. |
UdpTransportClientServiceCollectionExtensions | class | Extension methods for registering UDP transport services. |
UdpTransportOptions | class | Options for UDP transport configuration. |
UdpTransportPlugin | class | Plugin for the client side of the UDP transport, which a microservice connects with. |
class UdpFrameProtocol
public static class UdpFrameProtocol
Handles serialization and deserialization of frames for UDP transport. Frame format: [1-byte frame type][1-byte correlation length N][N bytes UTF-8 correlation id][remaining data] (TransportFrameHeader). The correlation id travels unchanged, so the gateway’s ULID correlations survive the round trip.
Members
| Member | Kind | Summary |
|---|---|---|
GetHeaderSize( | method | Gets the smallest valid datagram size: a header without a correlation id. |
ParseFrame( | method | Parses a frame from a datagram. |
SerializeFrame( | method | Serializes a frame to a datagram. |
method GetHeaderSize() #
GetHeaderSize() #public static int GetHeaderSize()
Gets the smallest valid datagram size: a header without a correlation id.
method ParseFrame(ReadOnlySpan<byte>) #
ParseFrame(ReadOnlySpan<byte>) #public static Frame ParseFrame(ReadOnlySpan<byte> data)
Parses a frame from a datagram.
Parameters
data: The datagram data.
Returns
The parsed frame.
Exceptions
Invalid: Thrown when the datagram header is malformed.Operation Exception
method SerializeFrame(Frame) #
SerializeFrame(Frame) #public static byte[] SerializeFrame(Frame frame)
Serializes a frame to a datagram.
Parameters
frame: The frame to serialize.
Returns
The serialized datagram bytes.
Exceptions
ArgumentException: The correlation id is longer thanTransportFrameHeader.UTF-8 bytes.MaxCorrelationIdBytes
class UdpTransportClient
public sealed class UdpTransportClient : ITransportClient, IMicroserviceTransport, IAsyncDisposable
UDP transport client implementation for microservices. UDP transport does not support streaming.
Members
constructor UdpTransportClient(IOptions<UdpTransportOptions>, ILogger<UdpTransportClient>) #
UdpTransportClient(IOptions<UdpTransportOptions>, ILogger<UdpTransportClient>) #public UdpTransportClient(IOptions<UdpTransportOptions> options, ILogger<UdpTransportClient> logger)
Initializes a new instance of the UdpTransportClientclass.
event OnCancelReceived #
OnCancelReceived #public event Func<Guid, string?, Task>? OnCancelReceived
Event raised when a CANCEL frame is received.
event OnRequestReceived #
OnRequestReceived #public event Func<Frame, CancellationToken, Task<Frame>>? OnRequestReceived
Event raised when a REQUEST frame is received.
method CancelAllInflight(string) #
CancelAllInflight(string) #public void CancelAllInflight(string reason)
Cancels all in-flight handlers.
method ConnectAsync(InstanceDescriptor, IReadOnlyList<EndpointDescriptor>, CancellationToken) #
ConnectAsync(InstanceDescriptor, IReadOnlyList<EndpointDescriptor>, CancellationToken) #public Task ConnectAsync(InstanceDescriptor instance, IReadOnlyList<EndpointDescriptor> endpoints, CancellationToken cancellationToken)
Connects to the gateway.
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 gateway and registers the instance, its endpoints, schemas and OpenAPI metadata in the HELLO datagram. The whole HELLO must fit one datagram (UdpTransportOptions.); a larger one fails with PayloadTooLargeExceptionbefore anything is sent.
Parameters
instance: The instance descriptor.endpoints: The endpoints to register.schemas: Schema definitions referenced by the endpoints.openApiInfo: OpenAPI metadata for the service.cancellationToken: Cancellation token.
method DisconnectAsync() #
DisconnectAsync() #public Task DisconnectAsync()
Disconnects from the gateway.
method DisposeAsync() #
DisposeAsync() #public ValueTask DisposeAsync()
See IAsync.
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 SendHeartbeatAsync(HeartbeatPayload, CancellationToken) #
SendHeartbeatAsync(HeartbeatPayload, CancellationToken) #public Task SendHeartbeatAsync(HeartbeatPayload heartbeat, CancellationToken cancellationToken)
Sends a heartbeat.
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.
class UdpTransportClientServiceCollectionExtensions
public static class UdpTransportClientServiceCollectionExtensions
Extension methods for registering UDP transport services.
Members
| Member | Kind | Summary |
|---|---|---|
AddUdpTransportClient( | extension method | Adds UDP transport client services to the service collection. |
extension method AddUdpTransportClient(IServiceCollection, Action<UdpTransportOptions>) #
AddUdpTransportClient(IServiceCollection, Action<UdpTransportOptions>) #public static IServiceCollection AddUdpTransportClient(this IServiceCollection services, Action<UdpTransportOptions>? configure = null)
Adds UDP transport client services to the service collection.
Parameters
services: The service collection.configure: Optional configuration action.
Returns
The service collection.
class UdpTransportOptions
public sealed class UdpTransportOptions
Options for UDP transport configuration.
Members
| Member | Kind | Summary |
|---|---|---|
UdpTransportOptions( | constructor | Creates an instance of UdpTransportOptions. |
AllowBroadcast | property | Gets or sets whether to allow broadcast. |
BindAddress | property | Gets or sets the bind address for the server. |
DefaultTimeout | property | Gets or sets the default timeout for requests. |
Host | property | Gets or sets the host to connect to (client only). |
MaxDatagramSize | property | Gets or sets the maximum datagram size in bytes. |
Port | property | Gets or sets the port to listen on/connect to. |
ReceiveBufferSize | property | Gets or sets the receive buffer size. |
SendBufferSize | property | Gets or sets the send buffer size. |
constructor UdpTransportOptions() #
UdpTransportOptions() #public UdpTransportOptions()
Creates an instance of UdpTransportOptions.
property AllowBroadcast #
AllowBroadcast #public bool AllowBroadcast { get; set; }
Gets or sets whether to allow broadcast.
property BindAddress #
BindAddress #public IPAddress BindAddress { get; set; }
Gets or sets the bind address for the server.
property DefaultTimeout #
DefaultTimeout #public TimeSpan DefaultTimeout { get; set; }
Gets or sets the default timeout for requests.
property Host #
Host #public string? Host { get; set; }
Gets or sets the host to connect to (client only).
property MaxDatagramSize #
MaxDatagramSize #public int MaxDatagramSize { get; set; }
Gets or sets the maximum datagram size in bytes. Conservative default well under typical MTU of 1500 bytes.
property Port #
Port #public int Port { get; set; }
Gets or sets the port to listen on/connect to. Default: TransportDefaultPorts.(5102), the gateway options’ default.
property ReceiveBufferSize #
ReceiveBufferSize #public int ReceiveBufferSize { get; set; }
Gets or sets the receive buffer size.
property SendBufferSize #
SendBufferSize #public int SendBufferSize { get; set; }
Gets or sets the send buffer size.
class UdpTransportPlugin
public sealed class UdpTransportPlugin : IRouterTransportPlugin
Plugin for the client side of the UDP transport, which a microservice connects with. The server side is Udp in Stella; both carry the transport name udp.
Members
| Member | Kind | Summary |
|---|---|---|
UdpTransportPlugin( | constructor | Creates an instance of UdpTransportPlugin. |
AllowInsecureTransportsEnvVar | constant | Environment variable that enables loading the UDP transport plugin. |
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. |
IsInsecureTransportsAllowed( | method | Returns true when UdpTransportPlugin.is set to a truthy value (case-insensitive: true, 1, yes). |
Register( | method | Registers transport services into the DI container for the side the context asks for. |
RegisterShared( | method | The registration the client and the server plugin of the UDP transport share: the insecure-transport guard (UdpTransportPlugin.) and the UdpTransportOptionsbinding of the context’s configuration section (Router:Transport:Udp when the context names none). |
constructor UdpTransportPlugin() #
UdpTransportPlugin() #public UdpTransportPlugin()
Creates an instance of UdpTransportPlugin.
constant AllowInsecureTransportsEnvVar #
AllowInsecureTransportsEnvVar #public const string AllowInsecureTransportsEnvVar = "STELLAOPS_ROUTER_ALLOW_INSECURE_TRANSPORTS"
Environment variable that enables loading the UDP transport plugin. UDP is unencrypted, unauthenticated, and unordered at the network layer; the runtime guard refuses to register the plugin unless the operator explicitly opts 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 IsInsecureTransportsAllowed() #
IsInsecureTransportsAllowed() #public static bool IsInsecureTransportsAllowed()
Returns true when UdpTransportPlugin.is set to a truthy value (case-insensitive: true, 1, yes).
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
method RegisterShared(RouterTransportRegistrationContext, Type) #
RegisterShared(RouterTransportRegistrationContext, Type) #public static void RegisterShared(RouterTransportRegistrationContext context, Type loggerCategory)
The registration the client and the server plugin of the UDP transport share: the insecure-transport guard (UdpTransportPlugin.) and the UdpTransportOptionsbinding of the context’s configuration section (Router:Transport:Udp when the context names none). Both plugins call it from UdpTransportPlugin.; a plugin for either side of the transport calls it the same way.
Parameters
context: The registration context of the plugin.loggerCategory: The logger category of the warning written when the guard is open.
Exceptions
Invalid: The insecure-transport guard is closed.Operation Exception