public static ExtractHeaders ( Message msmqMessage ) : string>.Dictionary |
||
msmqMessage | Message | |
Résultat | string>.Dictionary |
public void Should_fetch_the_replyToAddress_from_responsequeue_for_backwards_compatibility() { var message = MsmqUtilities.Convert(new OutgoingMessage("message id", new Dictionary <string, string>(), new byte[0]), new DispatchOptions(new UnicastAddressTag("destination"), DispatchConsistency.Default)); message.ResponseQueue = new MessageQueue(new MsmqAddress("local", Environment.MachineName).FullPath); var headers = MsmqUtilities.ExtractHeaders(message); Assert.AreEqual("local@" + Environment.MachineName, headers[Headers.ReplyToAddress]); }
public void Should_fetch_the_replyToAddress_from_responsequeue_for_backwards_compatibility() { Message message = MsmqUtilities.Convert( new OutgoingMessage("message id", new Dictionary <string, string>(), new byte[0])); message.ResponseQueue = new MessageQueue(new MsmqAddress("local", RuntimeEnvironment.MachineName).FullPath); Dictionary <string, string> headers = MsmqUtilities.ExtractHeaders(message); Assert.AreEqual("local@" + RuntimeEnvironment.MachineName, headers[Headers.ReplyToAddress]); }
public void Should_set_messageIntent_if_header_not_present() { Message message = MsmqUtilities.Convert( new OutgoingMessage("message id", new Dictionary <string, string> (), new byte[0])); message.AppSpecific = 3; //Send = 1, Publish = 2, Subscribe = 3, Unsubscribe = 4 and Reply = 5 Dictionary <string, string> headers = MsmqUtilities.ExtractHeaders(message); Assert.AreEqual("Subscribe", headers[Headers.MessageIntent]); }
public void Should_convert_a_message_back_even_if_special_characters_are_contained_in_the_headers() { var expected = $"Can u see this '{(char)0x19}' character."; var message = MsmqUtilities.Convert(new OutgoingMessage("message id", new Dictionary <string, string> { { "NServiceBus.ExceptionInfo.Message", expected } }, new byte[0]), new DispatchProperties()); var headers = MsmqUtilities.ExtractHeaders(message); Assert.AreEqual(expected, headers["NServiceBus.ExceptionInfo.Message"]); }
public void Should_not_override_replyToAddress() { Message message = MsmqUtilities.Convert( new OutgoingMessage("message id", new Dictionary <string, string> { { Headers.ReplyToAddress, "SomeAddress" } }, new byte[0])); message.ResponseQueue = new MessageQueue(new MsmqAddress("local", RuntimeEnvironment.MachineName).FullPath); Dictionary <string, string> headers = MsmqUtilities.ExtractHeaders(message); Assert.AreEqual("SomeAddress", headers[Headers.ReplyToAddress]); }
public void Should_convert_a_message_back_even_if_special_characters_are_contained_in_the_headers() { var expected = $"Can u see this '{(char) 0x19}' character."; var options = new DispatchOptions(new UnicastAddressTag("destination"), DispatchConsistency.Default); var message = MsmqUtilities.Convert(new OutgoingMessage("message id", new Dictionary <string, string> { { "NServiceBus.ExceptionInfo.Message", expected } }, new byte[0]), options); var headers = MsmqUtilities.ExtractHeaders(message); Assert.AreEqual(expected, headers["NServiceBus.ExceptionInfo.Message"]); }
public void Should_not_override_messageIntent() { var message = MsmqUtilities.Convert( new OutgoingMessage("message id", new Dictionary <string, string> { { Headers.MessageIntent, MessageIntentEnum.Send.ToString() } }, new byte[0]), new DispatchProperties()); message.AppSpecific = 3; //Send = 1, Publish = 2, Subscribe = 3, Unsubscribe = 4 and Reply = 5 var headers = MsmqUtilities.ExtractHeaders(message); Assert.AreEqual("Send", headers[Headers.MessageIntent]); }
public void Should_convert_message_headers_that_contain_nulls_at_the_end() { var expected = "Hello World"; Console.Out.WriteLine(sizeof(char)); var message = MsmqUtilities.Convert(new OutgoingMessage("message id", new Dictionary <string, string> { { "NServiceBus.ExceptionInfo.Message", expected } }, new byte[0]), new DispatchProperties()); var bufferWithNulls = new byte[message.Extension.Length + (10 * sizeof(char))]; Buffer.BlockCopy(message.Extension, 0, bufferWithNulls, 0, bufferWithNulls.Length - (10 * sizeof(char))); message.Extension = bufferWithNulls; var headers = MsmqUtilities.ExtractHeaders(message); Assert.AreEqual(expected, headers["NServiceBus.ExceptionInfo.Message"]); }
public void Should_deserialize_if_trailing_bogus_data() { var expected = "Hello World"; var message = MsmqUtilities.Convert(new OutgoingMessage("message id", new Dictionary <string, string> { { "NServiceBus.ExceptionInfo.Message", expected } }, new byte[0]), new DispatchProperties()); var r = new Random(); var bufferWithNulls = new byte[message.Extension.Length + (10 * sizeof(char))]; r.NextBytes(bufferWithNulls); Buffer.BlockCopy(message.Extension, 0, bufferWithNulls, 0, bufferWithNulls.Length - (10 * sizeof(char))); message.Extension = bufferWithNulls; var headers = MsmqUtilities.ExtractHeaders(message); Assert.AreEqual(expected, headers["NServiceBus.ExceptionInfo.Message"]); }
/// <summary> /// May throw a timeout exception if a message with the given id cannot be found. /// </summary> public void ReturnMessageToSourceQueue(string messageId) { using (var scope = new TransactionScope()) { try { var message = queue.ReceiveById(messageId, TimeoutDuration, MessageQueueTransactionType.Automatic); var headers = MsmqUtilities.ExtractHeaders(message); string failedQ; if (!headers.TryGetValue(Headers.FailedQ, out failedQ)) { Console.WriteLine("ERROR: Message does not have a header indicating from which queue it came. Cannot be automatically returned to queue."); return; } using (var q = new MessageQueue(MsmqUtilities.GetFullPath(MsmqAddress.Parse(failedQ)))) { q.Send(message, MessageQueueTransactionType.Automatic); } Console.WriteLine("Success."); scope.Complete(); } catch (MessageQueueException ex) { if (ex.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout) { Console.WriteLine(NoMessageFoundErrorFormat, messageId); uint messageCount = 0; foreach (var m in queue.GetAllMessages()) { messageCount++; var headers = MsmqUtilities.ExtractHeaders(m); var originalId = GetOriginalId(headers); if (string.IsNullOrEmpty(originalId) || messageId != originalId) { if (messageCount % ProgressInterval == 0) { Console.Write("."); } continue; } Console.WriteLine(); Console.WriteLine("Found message - going to return to queue."); using (var tx = new TransactionScope()) { var failedQueue = headers[Headers.FailedQ]; using (var q = new MessageQueue(MsmqUtilities.GetFullPath(MsmqAddress.Parse(failedQueue)))) { q.Send(m, MessageQueueTransactionType.Automatic); } queue.ReceiveByLookupId(MessageLookupAction.Current, m.LookupId, MessageQueueTransactionType.Automatic); tx.Complete(); } Console.WriteLine("Success."); scope.Complete(); return; } Console.WriteLine(); Console.WriteLine(NoMessageFoundInHeadersErrorFormat, messageId); } } } }