public void Send(OutgoingTransportMessage transportMessage, IEnumerable<string> addresses) { foreach (var queueName in addresses) { var _sendQueue = InMemoryQueueTransportReceiver.queues.GetOrAdd(queueName, new ConcurrentQueue<object>()); var _sendQueueNotifier = InMemoryQueueTransportReceiver.queueNotifiers.GetOrAdd(queueName, new AutoResetEvent(false)); _sendQueue.Enqueue(transportMessage.Message); _sendQueueNotifier.Set(); } }
public void Send(OutgoingTransportMessage transportMessage, IEnumerable<string> addresses) { var messageBuffer = messageEncoder.Encode(transportMessage.Message); var message = new Message(messageBuffer); message.Header = new Header(); message.Header.Durable = true; message.Properties = new Properties(); message.Properties.CreationTime = DateTime.UtcNow; message.Properties.MessageId = Guid.NewGuid().ToString(); message.Properties.ReplyTo = "TODO"; message.ApplicationProperties = new ApplicationProperties(); message.ApplicationProperties["LightRail.ContentType"] = messageEncoder.ContentType; message.ApplicationProperties["LightRail.EnclosedMessageTypes"] = string.Join(",", messageMapper.GetEnclosedMessageTypes(transportMessage.Message.GetType()).Distinct()); foreach (var pair in transportMessage.Headers) { message.ApplicationProperties[pair.Key] = pair.Value; } var connection = new Connection(amqpAddress); var session = new Session(connection); // Azure does not support Amqp transactions "The server was unable to process the request; please retry the operation. If the problem persists, please contact your Service Bus administrator and provide the tracking id..TrackingId:583da4f8d58d4fa59dc9521c6f799cb8_GWIN-AN5B307EEHM,TimeStamp:11.7.2014. 7:44:17" try { foreach (var address in addresses) { logger.Info("Sending Message {0} to {1}", message.Properties.MessageId, address); var senderLink = new SenderLink(session, Guid.NewGuid().ToString(), address); try { senderLink.Send(message); } finally { senderLink.Close(); } } } finally { session.Close(); connection.Close(); } }
public void Send(OutgoingTransportMessage transportMessage, IEnumerable<string> addresses) { var transaction = SqlServerTransactionManager.TryGetTransactionForCurrentTask(); var commitAndDisposeTransaction = false; if (transaction == null) { transaction = SqlServerTransactionManager.BeginTransaction(ConnectionString); commitAndDisposeTransaction = true; } try { transportMessage.Headers[StandardHeaders.TimeSent] = DateTime.UtcNow.ToString("o"); if (!transportMessage.Headers.ContainsKey(StandardHeaders.ReplyToAddress)) { transportMessage.Headers[StandardHeaders.ReplyToAddress] = this.ServiceBrokerSendingService; } transportMessage.Headers[StandardHeaders.OriginatingAddress] = this.ServiceBrokerSendingService; transportMessage.Headers[StandardHeaders.ContentType] = messageEncoder.ContentType; transportMessage.Headers[StandardHeaders.EnclosedMessageTypes] = string.Join(",", messageMapper.GetEnclosedMessageTypes(transportMessage.Message.GetType()).Distinct()); using (var stream = new MemoryStream()) { var encodedMessage = messageEncoder.EncodeAsString(transportMessage.Message); FastXmlTransportMessageSerializer.Serialize(transportMessage.Headers, encodedMessage, stream); var messageBuffer = stream.ToArray(); foreach (var destination in addresses) { var conversationHandle = ServiceBrokerWrapper.SendOne( transaction: transaction , initiatorServiceName: ServiceBrokerSendingService , targetServiceName: destination , messageContractName: ServiceBrokerContract , messageType: ServiceBrokerMessageType , body: messageBuffer); #if DEBUG logger.Debug(string.Format("Sending message {0} with Handle {1} to Service Named {2}.", transportMessage.Message.GetType().AssemblyQualifiedName, conversationHandle, destination)); logger.Debug(string.Format("ToString() of the message yields: {0}\n" + "Message headers:\n{1}", transportMessage.Message.ToString(), string.Join(", ", transportMessage.Headers.Select(h => h.Key + ":" + h.Value).ToArray()))); #endif } } if (commitAndDisposeTransaction) { SqlServerTransactionManager.CommitTransactionAndDisposeConnection(transaction); } } catch (Exception) { if (commitAndDisposeTransaction) { SqlServerTransactionManager.TryForceDisposeTransactionAndConnection(transaction); } throw; } }