Class MessageRouterBase
Base class for message routers.
Inherited Members
Namespace: Kephas.Messaging.Distributed.Routing
Assembly: Kephas.Messaging.dll
Syntax
public abstract class MessageRouterBase : Loggable, ILoggable, IMessageRouter, IDisposable
Constructors
| Improve this Doc View SourceMessageRouterBase(IMessageProcessor, IExportFactory<IBrokeredMessageBuilder>)
Initializes a new instance of the MessageRouterBase class.
Declaration
protected MessageRouterBase(IMessageProcessor messageProcessor, IExportFactory<IBrokeredMessageBuilder> messageBuilderFactory)
Parameters
Type | Name | Description |
---|---|---|
IMessageProcessor | messageProcessor | The message processor. |
IExportFactory<IBrokeredMessageBuilder> | messageBuilderFactory | The message builder factory. |
Properties
| Improve this Doc View SourceMessageProcessor
Gets the message processor.
Declaration
public IMessageProcessor MessageProcessor { get; }
Property Value
Type | Description |
---|---|
IMessageProcessor | The message processor. |
Methods
| Improve this Doc View SourceCreateBrokeredMessageBuilder(IContext)
Creates a brokered messsage builder.
Declaration
protected virtual IBrokeredMessageBuilder CreateBrokeredMessageBuilder(IContext context)
Parameters
Type | Name | Description |
---|---|---|
IContext | context | The publishing context. |
Returns
Type | Description |
---|---|
IBrokeredMessageBuilder | The new brokered messsage builder. |
DispatchAsync(IBrokeredMessage, IContext, CancellationToken)
Sends the brokered message asynchronously over the physical medium.
Declaration
public virtual Task<(RoutingInstruction action, IMessage reply)> DispatchAsync(IBrokeredMessage brokeredMessage, IContext context, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
IBrokeredMessage | brokeredMessage | The brokered message. |
IContext | context | The routing context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.ValueTuple<RoutingInstruction, IMessage>> | The asynchronous result yielding an action to take further and an optional reply. |
Remarks
This method is invoked by the message broker when it identifies this router as handler for a brokered message. The router needs to send the message through the physical medium and, if necessary, prepare a response.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Dispose(Boolean)
Releases the unmanaged resources used by the MessageRouterBase and optionally releases the managed resources.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | True to release both managed and unmanaged resources; false to release only unmanaged resources. |
OnReplyReceived(ReplyReceivedEventArgs)
Raises the reply received event.
Declaration
protected virtual void OnReplyReceived(ReplyReceivedEventArgs eventArgs)
Parameters
Type | Name | Description |
---|---|---|
ReplyReceivedEventArgs | eventArgs | Event information to send to registered event handlers. |
ProcessAsync(IBrokeredMessage, IContext, CancellationToken)
Processes the brokered message locally, asynchronously.
Declaration
protected virtual Task<IMessage> ProcessAsync(IBrokeredMessage brokeredMessage, IContext context, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
IBrokeredMessage | brokeredMessage | The brokered message. |
IContext | context | The routing context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IMessage> | An asynchronous result that yields the reply message. |
RouteInputAsync(IBrokeredMessage, IContext, CancellationToken)
Routes the message received from the input queue asynchronously.
Declaration
protected virtual Task<(RoutingInstruction action, IMessage reply)> RouteInputAsync(IBrokeredMessage brokeredMessage, IContext context, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
IBrokeredMessage | brokeredMessage | The brokered message. |
IContext | context | The routing context. |
System.Threading.CancellationToken | cancellationToken | A token that allows processing to be cancelled. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.ValueTuple<RoutingInstruction, IMessage>> | An asynchronous result. |
Remarks
This method is called by the input queue when a message is received. For a reply, the router notifies the message broker, otherwise it calls the message processor to handle the message. Depending whether the message is one-way or not, a reply is routed through the output queue.
RouteOutputAsync(IBrokeredMessage, IContext, CancellationToken)
Routes the brokered message asynchronously, typically over the physical medium.
Declaration
protected abstract Task<(RoutingInstruction action, IMessage reply)> RouteOutputAsync(IBrokeredMessage brokeredMessage, IContext context, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
IBrokeredMessage | brokeredMessage | The brokered message. |
IContext | context | The send context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.ValueTuple<RoutingInstruction, IMessage>> | The asynchronous result yielding an action to take further and an optional reply. |
Remarks
The one-way handling is performed in the DispatchAsync(IBrokeredMessage, IContext, CancellationToken) method, here the message is purely routed through the transport medium.
Events
| Improve this Doc View SourceReplyReceived
Occurs when a reply for is received to match a request sent from the container message broker.
Declaration
public event EventHandler<ReplyReceivedEventArgs> ReplyReceived
Event Type
Type | Description |
---|---|
System.EventHandler<ReplyReceivedEventArgs> |