static void MoveMessage(Message message, string destinationQueueName, bool leaveCopyInSourceQueue) { var sourceQueuePath = message.QueuePath; var destinationQueuePath = MsmqUtil.GetFullPath(destinationQueueName); using (var transaction = new MessageQueueTransaction()) { transaction.Begin(); try { var sourceQueue = new MessageQueue(sourceQueuePath) { MessageReadPropertyFilter = DefaultFilter() }; var destinationQueue = new MessageQueue(destinationQueuePath); var msmqMessage = sourceQueue.ReceiveById(message.Id, transaction); destinationQueue.Send(msmqMessage, transaction); if (leaveCopyInSourceQueue) { sourceQueue.Send(msmqMessage, transaction); } transaction.Commit(); } catch { transaction.Abort(); throw; } } Messenger.Default.Send(new MessageMoved(message, sourceQueuePath, destinationQueuePath, leaveCopyInSourceQueue)); }
public void CanSendOldFormat() { _bus.Advanced.Routing.Send(_oldEndpoint, new OldSchoolMessage { KeyChar = "g" }).Wait(); using (var queue = new MessageQueue(MsmqUtil.GetFullPath(_oldEndpoint))) { var message = queue.GetNextMessage(); using (var streamReader = new StreamReader(message.BodyStream, Encoding.UTF7)) { var jsonText = streamReader.ReadToEnd(); Assert.That(jsonText.ToNormalizedJson(), Is.EqualTo(ValidLegacyRebusMessage.ToNormalizedJson())); } var headers = message.DeserializeHeaders(); Console.WriteLine(@"Headers: {0}", string.Join(Environment.NewLine, headers.Select(kvp => string.Format(" {0}: {1}", kvp.Key, kvp.Value)))); Assert.That(headers["rebus-msg-id"], Is.Not.Empty); Assert.That(headers["rebus-content-type"], Is.EqualTo("text/json")); Assert.That(headers["rebus-encoding"], Is.EqualTo("utf-7")); Assert.That(headers["rebus-return-address"], Is.EqualTo(_newEndpoint + "@" + Environment.MachineName)); } }
public void CorrectlyHandlesMultipleLogicalMessages() { var gotWhat = new Dictionary <string, ManualResetEvent> { { "a", new ManualResetEvent(false) }, { "b", new ManualResetEvent(false) }, { "c", new ManualResetEvent(false) }, }; _activator.Handle <OldSchoolMessage>(async message => { gotWhat[message.KeyChar].Set(); }); var correlationId = Guid.NewGuid().ToString(); var messageId = Guid.NewGuid().ToString(); var headers = new Dictionary <string, string> { { "rebus-return-address", _newEndpoint }, { "rebus-correlation-id", correlationId }, { "rebus-msg-id", messageId }, { "rebus-content-type", "text/json" }, { "rebus-encoding", "utf-7" } }; var jsonBody = ValidLegacyRebusMessageWithMultipleLogicalMessages; using (var queue = new MessageQueue(MsmqUtil.GetFullPath(_newEndpoint))) { queue.SendLegacyRebusMessage(jsonBody, headers); } gotWhat.ForEach(kvp => kvp.Value.WaitOrDie(TimeSpan.FromSeconds(5), string.Format("Did not get message with KeyChar = '{0}'", kvp.Key))); }
public void CanReceiveOldFormat() { var gotIt = new ManualResetEvent(false); _activator.Handle <OldSchoolMessage>(async message => { if (message.KeyChar == "g") { gotIt.Set(); } }); var correlationId = Guid.NewGuid().ToString(); var messageId = Guid.NewGuid().ToString(); var headers = new Dictionary <string, string> { { "rebus-return-address", _newEndpoint }, { "rebus-correlation-id", correlationId }, { "rebus-msg-id", messageId }, { "rebus-content-type", "text/json" }, { "rebus-encoding", "utf-7" } }; var jsonBody = ValidLegacyRebusMessage; using (var queue = new MessageQueue(MsmqUtil.GetFullPath(_newEndpoint))) { queue.SendLegacyRebusMessage(jsonBody, headers); } gotIt.WaitOrDie(TimeSpan.FromSeconds(5)); }
void MoveMessage(Message message) { var sourceQueuePath = message.QueuePath; var destinationQueuePath = MsmqUtil.GetFullPath(message.Headers[Headers.SourceQueue]); using (var transaction = new MessageQueueTransaction()) { transaction.Begin(); try { var sourceQueue = new MessageQueue(sourceQueuePath) { MessageReadPropertyFilter = DefaultFilter() }; var destinationQueue = new MessageQueue(destinationQueuePath); var msmqMessage = sourceQueue.ReceiveById(message.Id, transaction); destinationQueue.Send(msmqMessage, transaction); transaction.Commit(); } catch { transaction.Abort(); throw; } } Messenger.Default.Send(new MessageMoved(message, sourceQueuePath, destinationQueuePath)); }
public void Send(string destinationQueueName, TransportMessageToSend message) { var recipientPath = MsmqUtil.GetFullPath(destinationQueueName); using (var outputQueue = GetMessageQueue(recipientPath)) { var transactionWrapper = GetOrCreateTransactionWrapper(); outputQueue.Send(message, transactionWrapper.MessageQueueTransaction); transactionWrapper.Commit(); } }
public async Task CanSubcribeWithOldSchoolSubscriptionRequest() { await _bus.Subscribe <string>(); await Task.Delay(500); using (var queue = new MessageQueue(MsmqUtil.GetFullPath(_oldEndpoint))) { var message = queue.GetNextMessage(); var headers = message.DeserializeHeaders(); using (var streamReader = new StreamReader(message.BodyStream, Encoding.UTF7)) { var jsonText = streamReader.ReadToEnd(); Assert.That(jsonText.ToNormalizedJson(), Is.EqualTo(ExpectedStringSubscriptionRequest.ToNormalizedJson())); } } }
public async Task CanHandleSubscriptionRequest() { var messageId = Guid.NewGuid().ToString(); var headers = new Dictionary <string, string> { { "rebus-return-address", _oldEndpoint }, { "rebus-msg-id", messageId }, { "rebus-content-type", "text/json" }, { "rebus-encoding", "utf-7" } }; using (var queue = new MessageQueue(MsmqUtil.GetFullPath(_newEndpoint))) { queue.SendLegacyRebusMessage(SubscriptionRequest, headers); } await Task.Delay(1000); var topic = "NewEndpoint.Messages.NewRequest, NewEndpoint.Messages"; Assert.That(_subscriptions.Count, Is.EqualTo(1)); Assert.That(_subscriptions[topic].Count, Is.EqualTo(1)); Assert.That(_subscriptions[topic].First(), Is.EqualTo(_oldEndpoint)); }