private static Task ExecuteHandler <TMessage>( TMessage message, IMessageHandler <TMessage> handler, MessageHandlerContext context) { return(handler.Handle(message, context)); }
public async Task Dispatch(TransportLevelMessage message) { var registration = GetMessageRegistrationFor(message); var unitOfWork = _unitOfWorkFactory.CreateForHandlerType(registration.HandlerInstanceType); if (unitOfWork == null) { throw new UnableToResolveUnitOfWorkForHandlerException($"Error! Unable to create unit of work for handler type \"{registration.HandlerInstanceType.FullName}\"."); } var messageInstance = message.ReadDataAs(registration.MessageInstanceType); var context = new MessageHandlerContext(message.Metadata); await unitOfWork.Run(async handler => { if (handler == null) { throw new InvalidMessageHandlerException($"Error! Message handler of type \"{registration.HandlerInstanceType.FullName}\" not instantiated in unit of work and message instance type of \"{registration.MessageInstanceType}\" for message type \"{registration.MessageType}\" can therefor not be handled."); } // TODO -- verify that the handler is in fact an implementation of IMessageHandler<registration.MessageInstanceType> to provider sane error messages. await ExecuteHandler((dynamic)messageInstance, (dynamic)handler, context); }); }
/// <summary> /// Logs a debug message with the Id and Type from the provided <paramref name="context"/>, and returns a completed task /// </summary> public Task Handle(object _, MessageHandlerContext context) { Logger.LogInformation( "Dafda is ignoring a message of type {messageType} with id {messageId}", context.MessageType, context.MessageId); return(Task.CompletedTask); }