Coordinator classes
RequestDispatcher
Public class. The single entry point of the system. It owns a RequestTracker and a RequestBus, and is the only class other systems call to send requests or deliver responses.
- Handlers are registered per domain with
Registerand removed withUnregister. The dispatcher forwards these calls to theRequestBus. Asktracks the request and then sends it on the bus.Replyresolves the pending request and invokes its callback. It logs a warning when no pending request matches.- It is held by
BusRegistry, so systems normally reach it throughServiceLocator.GetBusRegistry().RequestDispatcher.
RequestTracker
Internal class. Holds requests that have been sent but not yet answered, keyed by ID.
Trackassigns the next ID, sets it on the request, and stores the request.TryResolveremoves and returns the request that a response answers.- It is used only by
RequestDispatcher.
RequestBus
Internal class that extends MessageBus<IRequest, Domain>. It routes each request by its TargetDomain.
Sendpasses the request to the base class'sRoutemethod.GetRoutingKeyreturns the request'sTargetDomain.- The base class stores the handler per domain, delivers the request when a handler is registered, and queues it otherwise.
RequestDispatcherowns it. Other systems never reference it directly.
Data classes
Request
Public sealed class. Carries a target domain, a verb, an optional payload message, and an optional response callback.
- The
Idis set byRequestTrackerthroughSetIdand cannot be set by the sender. GetResponseCallbackgives the dispatcher access to the callback.- The
Paramsbag it inherits fromMessagecan be filled before sending.
Response
Public class. Carries the ID of the answered request, a RequestStatus, and a reason for rejections.
- Created through
Response.AcceptedorResponse.Rejected, using the request's ID. - Passed to the sender's callback, and to
RequestDispatcher.Reply.
RequestStatus
Public enum with the values Accepted and Rejected. Read from Response.GetRequestStatus.
Interfaces
IRequest
Public interface describing what a receiving system can read from a request. RequestBus uses TargetDomain as the routing key, and handlers read Verb, Payload, and Params.
IRequestHandler
Public interface with HandleRequest(IRequest req). It is part of the public contract, but RequestDispatcher.Register takes an Action<IRequest> delegate and does not reference it. A system can implement the interface and register its HandleRequest method as the delegate.
Interaction with dependency classes
- BusRegistry. Holds the
RequestDispatcherproperty, which is how other systems find the request system throughServiceLocator. - ServiceLocator. Provides the
BusRegistryused byBusUtilityand byMessageBusto reach theSignalBus. - BusUtility.
Send(Request)forwards toRequestDispatcher.Ask.SendMessage(Message)routesRequestinstances to that method. The source has a TODO to merge this switch into a single send. - MessageBus. The base class of
RequestBus. It stores handlers, queues messages, logs queueing, and releases queued messages in order when a handler registers. - SignalBus. Used by
MessageBusfor ready signals.RequestDispatcherdoes not callSetMessageQueueReadySignal, so no ready gating applies to requests through this system. - Message and Params.
Requestderives fromMessage, which providesTargetDomainand theParamsbag.IRequestexposes both. - Domain. The routing key for requests, defined in the Contracts system.