Task Dispatch <TMessage, TOptions>(TMessage message, string destinationPath, TransactionContext transactionContext, TOptions options) where TMessage : IMessage where TOptions : RoutingOptions, new() { if (options == null) { options = new TOptions(); } if (string.IsNullOrWhiteSpace(options.ContentType)) { throw new ArgumentNullException(nameof(options.ContentType), "Message content type is required"); } var converter = _bodyConverterFactory.CreateBodyConverter(options.ContentType); var outbound = new OutboundBrokeredMessage(options.MessageId, message, options.ApplicationProperties, destinationPath, converter); return(_messageRouter.Route(outbound, transactionContext)); }
IEnumerable <OutboundBrokeredMessage> Dispatch <TMessage, TOptions>(IEnumerable <TMessage> messages, string destinationPath, TOptions options) where TMessage : IMessage where TOptions : RoutingOptions, new() { if (options == null) { options = new TOptions(); } if (string.IsNullOrWhiteSpace(options.ContentType)) { throw new ArgumentNullException(nameof(options.ContentType), "Message content type is required"); } var converter = _bodyConverterFactory.CreateBodyConverter(options.ContentType); foreach (var message in messages) { var destination = string.IsNullOrWhiteSpace(destinationPath) ? _brokeredMessageDetailProvider.GetMessageName(message.GetType()) : destinationPath; if (string.IsNullOrWhiteSpace(destination)) { throw new ArgumentNullException(nameof(destination), $"Routing destination is required. Use {typeof(BrokeredMessageAttribute).Name} or overload that accepts 'destinationPath'"); } OutboundBrokeredMessage outbound; if (string.IsNullOrWhiteSpace(options.MessageId)) { outbound = new OutboundBrokeredMessage(_messageIdGenerator, message, options.MessageContext, destination, converter); } else { outbound = new OutboundBrokeredMessage(options.MessageId, message, options.MessageContext, destination, converter); } yield return(outbound); } }