/// <summary> /// Enforce messaging rules. Make sure, the message can be used within the <see cref="IBus.Send(object[])"/>. /// </summary> /// <param name="messageType">Event, Command or message</param> /// <param name="messageIntent">The intent of the message</param> public static void AssertIsValidForSend(Type messageType, MessageIntentEnum messageIntent) { if (MessageConventionExtensions.IsEventType(messageType) && messageIntent != MessageIntentEnum.Publish) { throw new InvalidOperationException("Events can have multiple recipient so they should be published"); } }
/// <summary> /// Enforce messaging rules. Make sure, the message can be used within the <see cref="IBus.Send(object[])"/>. /// </summary> /// <param name="messageType">Event, Command or message</param> public static void AssertIsValidForSend(Type messageType, MessageIntentEnum messageIntent) { if (MessageConventionExtensions.IsEventType(messageType) && messageIntent != MessageIntentEnum.Publish) { throw new InvalidOperationException("Events can have multiple recipient so they should be published"); } }
public Task Route(MessageContext context, MessageIntentEnum intent, IRawEndpoint dispatcher) { var forwardedHeaders = new Dictionary <string, string>(context.Headers); string replyTo = null; if (!forwardedHeaders.TryGetValue(Headers.CorrelationId, out var correlationId)) { throw new UnforwardableMessageException($"The reply has to contain a '{Headers.CorrelationId}' header set by the bridge ramp when sending out the initial message."); } correlationId.DecodeTLV((t, v) => { if (t == "reply-to") { replyTo = v; } if (t == "id") { forwardedHeaders[Headers.CorrelationId] = v; } }); if (replyTo == null) { throw new UnforwardableMessageException("The reply message does not contain \'reply-to\' correlation parameter required to route the message."); } var outgoingMessage = new OutgoingMessage(context.MessageId, forwardedHeaders, context.Body); var operation = new TransportOperation(outgoingMessage, new UnicastAddressTag(replyTo)); return(dispatcher.Dispatch(new TransportOperations(operation), context.TransportTransaction, context.Extensions)); }
public Task Route(MessageContext context, MessageIntentEnum intent, IRawEndpoint dispatcher) { string replyTo = null; if (!context.Headers.TryGetValue(Headers.CorrelationId, out string correlationId)) { throw new UnforwardableMessageException($"The reply has to contain a '{Headers.CorrelationId}' header set by the bridge ramp when sending out the initial message."); } correlationId.DecodeTLV((t, v) => { if (t == "reply-to") { replyTo = v; } }); if (replyTo == null) { throw new UnforwardableMessageException($"The reply has to contain a '{Headers.CorrelationId}' header set by the bridge ramp when sending out the initial message."); } var outgoingMessage = new OutgoingMessage(context.MessageId, context.Headers, context.Body); var operation = new TransportOperation(outgoingMessage, new UnicastAddressTag(replyTo)); return(dispatcher.Dispatch(new TransportOperations(operation), context.TransportTransaction, context.Extensions)); }
/// <summary> /// Creates Transport Message. /// </summary> /// <returns>Transport Message.</returns> public static OutgoingMessage Create(MessageIntentEnum intent) { var message = new OutgoingMessage(CombGuid.Generate().ToString(), new Dictionary <string, string>(), new byte[0]); message.Headers[Headers.ControlMessageHeader] = bool.TrueString; message.Headers[Headers.MessageIntent] = intent.ToString(); return(message); }
/// <summary> /// Creates Transport Message. /// </summary> /// <returns>Transport Message.</returns> public static OutgoingMessage Create(MessageIntentEnum intent) { var message = new OutgoingMessage(CombGuid.Generate().ToString(), new Dictionary<string, string>(), new byte[0]); message.Headers[Headers.ControlMessageHeader] = Boolean.TrueString; message.Headers[Headers.MessageIntent] = intent.ToString(); return message; }
public IncomingMessageFromLegacyEndpoint(string nsbVersion, MessageIntentEnum msgIntent) : base( new Guid().ToString(), new Dictionary<string, string> { {NServiceBus.Headers.NServiceBusVersion, nsbVersion}, {NServiceBus.Headers.MessageIntent, msgIntent.ToString()} }, new byte[0]) { }
public IncomingMessageFromLegacyEndpoint(string nsbVersion, MessageIntentEnum msgIntent) : base( new Guid().ToString(), new Dictionary <string, string> { { NServiceBus.Headers.NServiceBusVersion, nsbVersion }, { NServiceBus.Headers.MessageIntent, msgIntent.ToString() } }, new byte[0]) { }
private ICallback SendMessage(Address address, string correlationId, MessageIntentEnum messageIntent, params object[] messages) { // loop only happens once foreach (var id in SendMessage(new List <Address> { address }, correlationId, messageIntent, messages)) { return(SetupCallback(id)); } return(null); }
IList <Site> GetDestinationSitesFor(Dictionary <string, string> headers, MessageIntentEnum intent) { if (intent == MessageIntentEnum.Reply) { return(OriginatingSiteHeaderRouter.GetDestinationSitesFor(headers).ToList()); } var conventionRoutes = KeyPrefixConventionSiteRouter.GetDestinationSitesFor(headers); var configuredRoutes = configRouter.GetDestinationSitesFor(headers); return(conventionRoutes.Concat(configuredRoutes).ToList()); }
public void Below_v4_3_0_should_return_value_for_all_intents(string nsbVersion, MessageIntentEnum intent) { var correlationId = new Guid().ToString(); var lookup = new RequestResponseStateLookup(); lookup.RegisterState(correlationId, new RequestResponseStateLookup.State()); var message = new IncomingMessageFromLegacyEndpoint(nsbVersion, intent); var incomingContext = new TestableIncomingLogicalMessageContext(); incomingContext.MessageHeaders.Add(Headers.CorrelationId, correlationId); var result = incomingContext.TryRemoveResponseStateBasedOnCorrelationId(message, lookup); Assert.IsTrue(result.HasValue); }
public async Task Route(MessageContext context, MessageIntentEnum intent, IRawEndpoint dispatcher) { var messageTypeString = GetSubscriptionMessageTypeFrom(context); if (string.IsNullOrEmpty(messageTypeString)) { throw new UnforwardableMessageException("Message intent is Subscribe, but the subscription message type header is missing."); } if (intent != MessageIntentEnum.Subscribe && intent != MessageIntentEnum.Unsubscribe) { throw new UnforwardableMessageException("Subscription messages need to have intent set to Subscribe/Unsubscribe."); } string subscriberAddress; string subscriberEndpoint = null; string publisherEndpoint; if (!context.Headers.TryGetValue("NServiceBus.Bridge.DestinationEndpoint", out publisherEndpoint)) { throw new UnforwardableMessageException("Subscription message does not contain the 'NServiceBus.Bridge.DestinationEndpoint' header."); } if (context.Headers.TryGetValue(Headers.SubscriberTransportAddress, out subscriberAddress)) { subscriberEndpoint = context.Headers[Headers.SubscriberEndpoint]; } else { subscriberAddress = GetReplyToAddress(context); } if (subscriberAddress == null) { throw new UnforwardableMessageException("Subscription message arrived without a valid ReplyToAddress."); } var subscriber = new Subscriber(subscriberAddress, subscriberEndpoint); var messageType = new MessageType(messageTypeString); if (intent == MessageIntentEnum.Subscribe) { await subscriptionStorage.Subscribe(subscriber, messageType, context.Extensions).ConfigureAwait(false); await ForwardSubscribe(subscriber, publisherEndpoint, messageTypeString, dispatcher).ConfigureAwait(false); } else { await subscriptionStorage.Unsubscribe(subscriber, messageType, context.Extensions).ConfigureAwait(false); await ForwardUnsubscribe(subscriber, publisherEndpoint, messageTypeString, dispatcher).ConfigureAwait(false); } }
public static TransportMessage DeserializeFromXml(OracleAQMessage message) { if (message == null) { return(null); } XmlDocument bodyDoc; using (OracleXmlType type = (OracleXmlType)message.Payload) { bodyDoc = type.GetXmlDocument(); } var bodySection = bodyDoc.DocumentElement.SelectSingleNode("Body").FirstChild as XmlCDataSection; var headerDictionary = new SerializableDictionary <string, string>(); var headerSection = bodyDoc.DocumentElement.SelectSingleNode("Headers"); if (headerSection != null) { headerDictionary.SetXml(headerSection.InnerXml); } Address replyToAddress = null; var replyToAddressSection = bodyDoc.DocumentElement.SelectSingleNode("ReplyToAddress"); if (replyToAddressSection != null && !string.IsNullOrWhiteSpace(replyToAddressSection.InnerText)) { replyToAddress = Address.Parse(replyToAddressSection.InnerText.Trim()); } MessageIntentEnum messageIntent = default(MessageIntentEnum); var messageIntentSection = bodyDoc.DocumentElement.SelectSingleNode("MessageIntent"); if (messageIntentSection != null) { messageIntent = (MessageIntentEnum)Enum.Parse(typeof(MessageIntentEnum), messageIntentSection.InnerText); } var transportMessage = new TransportMessage(new Guid(message.MessageId).ToString(), headerDictionary) { Body = bodySection != null?Encoding.UTF8.GetBytes(bodySection.Data) : new byte[0], ReplyToAddress = replyToAddress, MessageIntent = messageIntent, }; return(transportMessage); }
private ICallback SendMessage(string destination, string correlationId, MessageIntentEnum messageIntent, params object[] messages) { if (messages == null || messages.Length == 0) { throw new InvalidOperationException("Cannot send an empty set of messages."); } if (destination == null) { throw new InvalidOperationException( string.Format("No destination specified for message {0}. Message cannot be sent. Check the UnicastBusConfig section in your config file and ensure that a MessageEndpointMapping exists for the message type.", messages[0].GetType().FullName)); } return(SendMessage(Address.Parse(destination), correlationId, messageIntent, messages)); }
private void SendMessage(string destination, Guid?correlationId, MessageIntentEnum messageIntent, params object[] messages) { if (messages == null || messages.Length == 0) { throw new InvalidOperationException("Cannot send an empty set of messages."); } if (string.IsNullOrEmpty(destination)) { throw new InvalidOperationException(string.Format("No destination specified for message {0}. Message cannot be sent.", messages[0].GetType().FullName)); } SendMessage(new List <string> { destination }, correlationId, messageIntent, messages); }
public SubscriptionAuthorization(EndpointConfiguration endpointConfiguration) { #region SubscriptionAuthorizer endpointConfiguration.UseTransport <MsmqTransport>() .SubscriptionAuthorizer(context => { string subscriptionMessageType = context.MessageHeaders[Headers.SubscriptionMessageType]; string messageIntent = context.MessageHeaders[Headers.MessageIntent]; MessageIntentEnum messageIntentEnum = (MessageIntentEnum)Enum.Parse(typeof(MessageIntentEnum), messageIntent, true); //messageIntentEnum will be either MessageIntentEnum.Unsubscribe or MessageIntentEnum.Subscribe string endpointName = context.MessageHeaders[Headers.SubscriberEndpoint] .ToLowerInvariant(); // true to allow false to decline return(true); }); #endregion }
public Task Route(MessageContext context, MessageIntentEnum intent, IRawEndpoint dispatcher) { string destinationEndpoint; if (!context.Headers.TryGetValue("NServiceBus.Bridge.DestinationEndpoint", out destinationEndpoint)) { throw new UnforwardableMessageException("Sent message does not contain the 'NServiceBus.Bridge.DestinationEndpoint' header."); } var address = SelectDestinationAddress(destinationEndpoint, i => dispatcher.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i))); context.Headers[Headers.ReplyToAddress] = dispatcher.TransportAddress; var outgoingMessage = new OutgoingMessage(context.MessageId, context.Headers, context.Body); var operation = new TransportOperation(outgoingMessage, new UnicastAddressTag(address)); return(dispatcher.Dispatch(new TransportOperations(operation), context.TransportTransaction, context.Extensions)); }
public async Task Route(MessageContext context, MessageIntentEnum intent, IRawEndpoint dispatcher) { string messageTypes; if (!context.Headers.TryGetValue(Headers.EnclosedMessageTypes, out messageTypes)) { throw new UnforwardableMessageException("Message need to have 'NServiceBus.EnclosedMessageTypes' header in order to be routed."); } var types = messageTypes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); var typeObjects = types.Select(t => new MessageType(t)); var subscribers = await subscriptionStorage.GetSubscriberAddressesForMessage(typeObjects, new ContextBag()).ConfigureAwait(false); var destinations = SelectDestinationsForEachEndpoint(subscribers); var outgoingMessage = new OutgoingMessage(context.MessageId, context.Headers, context.Body); var operations = destinations.Select(x => new TransportOperation(outgoingMessage, new UnicastAddressTag(x))); await dispatcher.Dispatch(new TransportOperations(operations.ToArray()), context.TransportTransaction, context.Extensions).ConfigureAwait(false); }
static async Task AsyncMain() { Console.Title = "Samples.PubSub.MyPublisher"; LogManager.Use <DefaultFactory>().Level(LogLevel.Info); EndpointConfiguration endpointConfiguration = new EndpointConfiguration("Samples.PubSub.MyPublisher"); endpointConfiguration.UseSerialization <JsonSerializer>(); endpointConfiguration.UsePersistence <InMemoryPersistence>(); #region SubscriptionAuthorizer var transport = endpointConfiguration.UseTransport <MsmqTransport>(); transport.SubscriptionAuthorizer(context => { string subscriptionType = context.MessageHeaders[Headers.MessageIntent]; MessageIntentEnum messageIntentEnum = (MessageIntentEnum)Enum.Parse(typeof(MessageIntentEnum), subscriptionType, true); if (messageIntentEnum == MessageIntentEnum.Unsubscribe) { return(true); } string lowerEndpointName = context.MessageHeaders[Headers.SubscriberEndpoint] .ToLowerInvariant(); return(lowerEndpointName.StartsWith("samples.pubsub.subscriber1") || lowerEndpointName.StartsWith("samples.pubsub.subscriber2")); }); #endregion endpointConfiguration.SendFailedMessagesTo("error"); endpointConfiguration.EnableInstallers(); IEndpointInstance endpoint = await Endpoint.Start(endpointConfiguration); try { await Start(endpoint); } finally { await endpoint.Stop(); } }
public Task Receive(MessageContext context, MessageIntentEnum intent) { var messageTypeString = GetSubscriptionMessageTypeFrom(context); if (string.IsNullOrEmpty(messageTypeString)) { throw new UnforwardableMessageException("Message intent is Subscribe, but the subscription message type header is missing."); } if (intent != MessageIntentEnum.Subscribe && intent != MessageIntentEnum.Unsubscribe) { throw new UnforwardableMessageException("Subscription messages need to have intent set to Subscribe/Unsubscribe."); } string subscriberEndpoint = null; if (context.Headers.TryGetValue(Headers.SubscriberTransportAddress, out var subscriberAddress)) { subscriberEndpoint = context.Headers[Headers.SubscriberEndpoint]; } else { subscriberAddress = GetReplyToAddress(context); } if (subscriberAddress == null) { throw new UnforwardableMessageException("Subscription message arrived without a valid ReplyToAddress."); } var subscriber = new Subscriber(subscriberAddress, subscriberEndpoint); var messageType = new MessageType(messageTypeString); if (intent == MessageIntentEnum.Subscribe) { return(ReceiveSubscribe(subscriber, messageType)); } return(ReceiveUnsubscribe(subscriber, messageType)); }
private static string GetDestinationKind(MessageIntentEnum intentValue, OutboundRoutingPolicy routingPolicy) { switch (intentValue) { case MessageIntentEnum.Send: return(ConvertPolicyToKind(routingPolicy.Sends)); case MessageIntentEnum.Publish: return(ConvertPolicyToKind(routingPolicy.Publishes)); case MessageIntentEnum.Subscribe: return(ConvertPolicyToKind(routingPolicy.Sends)); case MessageIntentEnum.Unsubscribe: return(ConvertPolicyToKind(routingPolicy.Sends)); case MessageIntentEnum.Reply: return(ConvertPolicyToKind(routingPolicy.Replies)); default: return(null); } }
static MessageContext CreateMessageContext(string messageType, string replyTo, MessageIntentEnum intent, string id, DateTime timestamp) { const string ResubscriptionIdHeader = "NServiceBus.Bridge.ResubscriptionId"; const string ResubscriptionTimestampHeader = "NServiceBus.Bridge.ResubscriptionTimestamp"; var headers = new Dictionary <string, string>(); if (messageType != null) { headers[Headers.SubscriptionMessageType] = messageType; } if (replyTo != null) { headers[Headers.ReplyToAddress] = replyTo; } headers[ResubscriptionIdHeader] = id; headers[ResubscriptionTimestampHeader] = timestamp.ToString("O"); headers[Headers.MessageIntent] = intent.ToString(); return(new MessageContext(Guid.NewGuid().ToString(), headers, new byte[0], new TransportTransaction(), new CancellationTokenSource(), new ContextBag())); }
/// <summary> /// Maps the account name to a QueueServiceClient, throwing when no mapping found. /// </summary> internal QueueServiceClient Map(QueueAddress address, MessageIntentEnum messageIntent) { if (registeredEndpoints.TryGetValue(address, out var accountInfo)) { return(accountInfo.QueueServiceClient); } var storageAccountAlias = address.Alias; if (aliasToAccountInfoMap.TryGetValue(storageAccountAlias, out accountInfo) == false) { // If this is a reply message with a connection string use the connection string to construct a queue service client. // This was a reply message coming from an older endpoint w/o aliases. if (messageIntent == MessageIntentEnum.Reply && CloudStorageAccount.TryParse(address.Alias, out _)) { return(new QueueServiceClient(address.Alias)); } throw new Exception($"No account was mapped under following name '{address.Alias}'. Please map it using .AccountRouting().AddAccount() method."); } return(accountInfo.QueueServiceClient); }
public FailedMessage.ProcessingAttempt CreateProcessingAttempt(Dictionary <string, string> headers, Dictionary <string, object> metadata, FailureDetails failureDetails, MessageIntentEnum intent, bool recoverable, string correlationId, string replyToAddress) { return(new FailedMessage.ProcessingAttempt { AttemptedAt = failureDetails.TimeOfFailure, FailureDetails = failureDetails, MessageMetadata = metadata, MessageId = headers[Headers.MessageId], Headers = headers, ReplyToAddress = replyToAddress, Recoverable = recoverable, CorrelationId = correlationId, MessageIntent = intent }); }
public SubscriptionBehavior(Action <SubscriptionEventArgs, TContext> action, TContext scenarioContext, MessageIntentEnum intentToHandle) { this.action = action; this.scenarioContext = scenarioContext; this.intentToHandle = intentToHandle; }
async Task Send(Subscriber subscriber, string publisherEndpoint, string messageType, MessageIntentEnum intent, IRawEndpoint dispatcher) { var publisherInstances = endpointInstances.FindInstances(publisherEndpoint); var publisherAddresses = publisherInstances.Select(i => dispatcher.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i))).ToArray(); foreach (var publisherAddress in publisherAddresses) { Logger.Debug( $"Sending {intent} request for {messageType} to {publisherAddress} on behalf of {subscriber.TransportAddress}."); var subscriptionMessage = ControlMessageFactory.Create(intent); subscriptionMessage.Headers[Headers.SubscriptionMessageType] = messageType; subscriptionMessage.Headers[Headers.ReplyToAddress] = dispatcher.TransportAddress; subscriptionMessage.Headers[Headers.SubscriberTransportAddress] = dispatcher.TransportAddress; subscriptionMessage.Headers[Headers.SubscriberEndpoint] = dispatcher.EndpointName; subscriptionMessage.Headers["NServiceBus.Bridge.DestinationEndpoint"] = publisherEndpoint; subscriptionMessage.Headers[Headers.TimeSent] = DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow); subscriptionMessage.Headers[Headers.NServiceBusVersion] = "6.3.1"; //The code has been copied from 6.3.1 var transportOperation = new TransportOperation(subscriptionMessage, new UnicastAddressTag(publisherAddress)); await dispatcher.Dispatch(new TransportOperations(transportOperation), new TransportTransaction(), new ContextBag()).ConfigureAwait(false); } }
static OutgoingMessage CreateMessage(string ultimateDestination, string messageType, string localAddress, string localEndpoint, string originalSubscriberAddress, string originalSubscriberEndpoint, MessageIntentEnum intent) { var subscriptionMessage = ControlMessageFactory.Create(intent); subscriptionMessage.Headers[Headers.SubscriptionMessageType] = messageType; subscriptionMessage.Headers[Headers.ReplyToAddress] = localAddress; if (localAddress != null) { subscriptionMessage.Headers[Headers.SubscriberTransportAddress] = localAddress; } subscriptionMessage.Headers["NServiceBus.Router.Migrator.OriginalSubscriberAddress"] = originalSubscriberAddress; subscriptionMessage.Headers["NServiceBus.Router.Migrator.OriginalSubscriberEndpoint"] = originalSubscriberEndpoint; subscriptionMessage.Headers[Headers.SubscriberEndpoint] = localEndpoint; subscriptionMessage.Headers[Headers.TimeSent] = DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow); subscriptionMessage.Headers[Headers.NServiceBusVersion] = "6.3.1"; //The code has been copied from 6.3.1 if (ultimateDestination != null) { subscriptionMessage.Headers["NServiceBus.Bridge.DestinationEndpoint"] = ultimateDestination; } return(subscriptionMessage); }
public void Below_v5_0_0_should_return_value_for_all_intents(string nsbVersion, MessageIntentEnum intent) { var correlationId = new Guid().ToString(); var lookup = new RequestResponseStateLookup(); lookup.RegisterState(correlationId, new RequestResponseStateLookup.State()); var message = new IncomingMessageFromLegacyEndpoint(nsbVersion, intent); var incomingContext = new TestableIncomingLogicalMessageContext(); incomingContext.MessageHeaders.Add(Headers.CorrelationId, correlationId); var result = incomingContext.TryRemoveResponseStateBasedOnCorrelationId(message, lookup); Assert.IsTrue(result.HasValue); }
async Task Send(Subscriber subscriber, string publisherEndpoint, string messageType, MessageIntentEnum intent, IRawEndpoint dispatcher, InterBridgeRoutingSettings forwarding) { var typeFullName = messageType.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).First(); if (!forwarding.PublisherTable.TryGetValue(typeFullName, out var nextHopEndpoint)) { return; } var subscriptionMessage = ControlMessageFactory.Create(intent); if (publisherEndpoint != null) { subscriptionMessage.Headers["NServiceBus.Bridge.DestinationEndpoint"] = publisherEndpoint; } subscriptionMessage.Headers[Headers.SubscriptionMessageType] = messageType; subscriptionMessage.Headers[Headers.ReplyToAddress] = dispatcher.TransportAddress; subscriptionMessage.Headers[Headers.SubscriberTransportAddress] = dispatcher.TransportAddress; subscriptionMessage.Headers[Headers.SubscriberEndpoint] = dispatcher.EndpointName; subscriptionMessage.Headers[Headers.TimeSent] = DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow); subscriptionMessage.Headers[Headers.NServiceBusVersion] = "6.3.1"; //The code has been copied from 6.3.1 var publisherInstances = endpointInstances.FindInstances(nextHopEndpoint); var publisherAddresses = publisherInstances.Select(i => dispatcher.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i))).ToArray(); foreach (var publisherAddress in publisherAddresses) { Logger.Debug( $"Sending {intent} request for {messageType} to {publisherAddress} on behalf of {subscriber.TransportAddress}."); var transportOperation = new TransportOperation(subscriptionMessage, new UnicastAddressTag(publisherAddress)); await dispatcher.Dispatch(new TransportOperations(transportOperation), new TransportTransaction(), new ContextBag()).ConfigureAwait(false); } }
public TransportMessageBuilder WithIntent(MessageIntentEnum intent) { message.MessageIntent = intent; return this; }
IEnumerable <string> SendMessage(List <Address> addresses, string correlationId, MessageIntentEnum messageIntent, params object[] messages) { if (messages.Length == 0) { return(Enumerable.Empty <string>()); } messages.ToList() .ForEach(message => MessagingBestPractices.AssertIsValidForSend(message.GetType(), messageIntent)); if (messages.Length > 1) { // Users can't send more than one message with a DataBusProperty in the same TransportMessage, Yes this is a limitation for now! var numberOfMessagesWithDataBusProperties = 0; foreach (var message in messages) { var hasAtLeastOneDataBusProperty = message.GetType().GetProperties().Any(MessageConventionExtensions.IsDataBusProperty); if (hasAtLeastOneDataBusProperty) { numberOfMessagesWithDataBusProperties++; } } if (numberOfMessagesWithDataBusProperties > 1) { throw new InvalidOperationException("This version of NServiceBus only supports sending up to one message with DataBusProperties per Send()."); } } addresses .ForEach(address => { if (address == Address.Undefined) { throw new InvalidOperationException("No destination specified for message(s): " + string.Join(";", messages.Select(m => m.GetType()))); } }); var result = new List <string>(); var toSend = new TransportMessage { MessageIntent = messageIntent }; if (!string.IsNullOrEmpty(correlationId)) { toSend.CorrelationId = correlationId; } MapTransportMessageFor(messages, toSend); foreach (var destination in addresses) { try { MessageSender.Send(toSend, destination); } catch (QueueNotFoundException ex) { throw new ConfigurationErrorsException("The destination queue '" + destination + "' could not be found. You may have misconfigured the destination for this kind of message (" + messages[0].GetType().FullName + ") in the MessageEndpointMappings of the UnicastBusConfig section in your configuration file. " + "It may also be the case that the given queue just hasn't been created yet, or has been deleted." , ex); } if (Log.IsDebugEnabled) { Log.Debug(string.Format("Sending message {0} with ID {1} to destination {2}.\n" + "ToString() of the message yields: {3}\n" + "Message headers:\n{4}", messages[0].GetType().AssemblyQualifiedName, toSend.Id, destination, messages[0], string.Join(", ", toSend.Headers.Select(h => h.Key + ":" + h.Value).ToArray()) )); } result.Add(toSend.Id); } if (MessagesSent != null) { MessagesSent(this, new MessagesEventArgs(messages)); } return(result); }
private void SendMessage(IEnumerable <string> destinations, Guid?correlationId, MessageIntentEnum messageIntent, params object[] messages) { if (destinations == null || !destinations.Any() || destinations.Any(x => string.IsNullOrEmpty(x))) { throw new InvalidOperationException("No destination specified for message(s): " + string.Join(";", messages.Select(m => m.GetType()))); } var toSend = new TransportMessage { CorrelationId = correlationId.HasValue ? correlationId.ToString() : null, MessageIntent = messageIntent }; MapTransportMessageFor(messages, toSend); transport.Send(toSend, destinations); OnMessageSent(transport, destinations, messages); }
public TransportMessageBuilder WithIntent(MessageIntentEnum intent) { message.MessageIntent = intent; return(this); }
public OutgoingMessageBuilder WithIntent(MessageIntentEnum intent) { return(WithHeader(Headers.MessageIntent, intent.ToString())); }
private static string GetDestinationKind(MessageIntentEnum intentValue, OutboundRoutingPolicy routingPolicy) => intentValue switch {