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(); } }
void ITransport.Send(OutgoingTransportMessage transportMessage, IEnumerable <string> destinations) { var transaction = openTransaction; // check for "ambient" transaction on current thread var commitAndDisposeTransaction = false; if (transaction == null) { transaction = BeginTransaction(); commitAndDisposeTransaction = true; } try { transportMessage.Headers[StandardHeaders.TimeSent] = DateTime.UtcNow.ToString("o"); transportMessage.Headers[StandardHeaders.ReplyToAddress] = this.ServiceBrokerService; transportMessage.Headers[StandardHeaders.OriginatingAddress] = this.ServiceBrokerService; using (var stream = new MemoryStream()) { FastXmlTransportMessageSerializer.Serialize(transportMessage, stream); var messageBuffer = stream.ToArray(); foreach (var destination in destinations) { var conversationHandle = ServiceBrokerWrapper.SendOne(transaction, ServiceBrokerService, destination, ServiceBrokerContract, ServiceBrokerMessageType, 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) { transaction.Commit(); } } finally { if (commitAndDisposeTransaction) { TryDisposeTransactionAndConnection(transaction); } } }
public void SendInternal <T>(T message, IEnumerable <string> addresses) { if (addresses.Count() == 0) { throw new ArgumentOutOfRangeException(nameof(addresses), "Must have an address to send the message to"); } if (message == null) { return; } var transportMessage = new OutgoingTransportMessage(new Dictionary <string, string>(), message); Transport.Send(transportMessage, addresses); }
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(); } }
string ITransport.RequestTimeoutMessage(int secondsToWait, OutgoingTransportMessage transportMessage) { var transaction = openTransaction; // check for "ambient" transaction on current thread var commitAndDisposeTransaction = false; if (transaction == null) { transaction = BeginTransaction(); commitAndDisposeTransaction = true; } try { transportMessage.Headers[StandardHeaders.TimeSent] = DateTime.UtcNow.ToString("o"); transportMessage.Headers[StandardHeaders.ReplyToAddress] = this.ServiceBrokerService; transportMessage.Headers[StandardHeaders.OriginatingAddress] = this.ServiceBrokerService; var conversationHandle = ServiceBrokerWrapper.BeginConversation(transaction, ServiceBrokerService, ServiceBrokerService); ServiceBrokerWrapper.BeginTimer(transaction, conversationHandle, secondsToWait); using (var stream = new MemoryStream()) { FastXmlTransportMessageSerializer.Serialize(transportMessage, stream); var messageBuffer = stream.ToArray(); PushTimeoutMessage(transaction, conversationHandle, messageBuffer, secondsToWait); } if (commitAndDisposeTransaction) { transaction.Commit(); } return(conversationHandle.ToString()); } finally { if (commitAndDisposeTransaction) { TryDisposeTransactionAndConnection(transaction); } } }
public void Send(OutgoingTransportMessage transportMessage, IEnumerable <string> destinations) { var transaction = openTransaction; // check for "ambient" transaction on current thread var commitAndDisposeTransaction = false; if (transaction == null) { transaction = new MessageQueueTransaction(); transaction.Begin(); commitAndDisposeTransaction = true; } try { using (var stream = new MemoryStream()) { var message = new Message(); FastXmlTransportMessageSerializer.Serialize(transportMessage, stream); stream.Position = 0; message.BodyStream = stream; message.Recoverable = true; message.ResponseQueue = new MessageQueue(MsmqUtilities.GetFullPath(InputQueue)); localQueue.Send(message, transaction); } if (commitAndDisposeTransaction) { transaction.Commit(); } } finally { if (commitAndDisposeTransaction) { TryDisposeTransaction(transaction); } } }
public string RequestTimeoutMessage(int secondsToWait, OutgoingTransportMessage transportMessage) { throw new NotImplementedException(); }
void ITransport.Send(OutgoingTransportMessage transportMessage, IEnumerable<string> destinations) { var transaction = openTransaction; // check for "ambient" transaction on current thread var commitAndDisposeTransaction = false; if (transaction == null) { transaction = BeginTransaction(); commitAndDisposeTransaction = true; } try { transportMessage.Headers[StandardHeaders.TimeSent] = DateTime.UtcNow.ToString("o"); transportMessage.Headers[StandardHeaders.ReplyToAddress] = this.ServiceBrokerService; transportMessage.Headers[StandardHeaders.OriginatingAddress] = this.ServiceBrokerService; using (var stream = new MemoryStream()) { FastXmlTransportMessageSerializer.Serialize(transportMessage, stream); var messageBuffer = stream.ToArray(); foreach (var destination in destinations) { var conversationHandle = ServiceBrokerWrapper.SendOne(transaction, ServiceBrokerService, destination, ServiceBrokerContract, ServiceBrokerMessageType, 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) { transaction.Commit(); } } finally { if (commitAndDisposeTransaction) { TryDisposeTransactionAndConnection(transaction); } } }
string ITransport.RequestTimeoutMessage(int secondsToWait, OutgoingTransportMessage transportMessage) { var transaction = openTransaction; // check for "ambient" transaction on current thread var commitAndDisposeTransaction = false; if (transaction == null) { transaction = BeginTransaction(); commitAndDisposeTransaction = true; } try { transportMessage.Headers[StandardHeaders.TimeSent] = DateTime.UtcNow.ToString("o"); transportMessage.Headers[StandardHeaders.ReplyToAddress] = this.ServiceBrokerService; transportMessage.Headers[StandardHeaders.OriginatingAddress] = this.ServiceBrokerService; var conversationHandle = ServiceBrokerWrapper.BeginConversation(transaction, ServiceBrokerService, ServiceBrokerService); ServiceBrokerWrapper.BeginTimer(transaction, conversationHandle, secondsToWait); using (var stream = new MemoryStream()) { FastXmlTransportMessageSerializer.Serialize(transportMessage, stream); var messageBuffer = stream.ToArray(); PushTimeoutMessage(transaction, conversationHandle, messageBuffer, secondsToWait); } if (commitAndDisposeTransaction) { transaction.Commit(); } return conversationHandle.ToString(); } finally { if (commitAndDisposeTransaction) { TryDisposeTransactionAndConnection(transaction); } } }
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; } }