public static ServiceBusRuntime BinaryMsmqRuntime() { // Drop test queues if they already exist if (MsmqMessageDeliveryQueue.Exists(_testQueuePath)) { MsmqMessageDeliveryQueue.Delete(_testQueuePath); } if (MsmqMessageDeliveryQueue.Exists(_retryQueuePath)) { MsmqMessageDeliveryQueue.Delete(_retryQueuePath); } if (MsmqMessageDeliveryQueue.Exists(_failQueuePath)) { MsmqMessageDeliveryQueue.Delete(_failQueuePath); } // Create test queues MsmqMessageDeliveryQueue.Create(_testQueuePath); MsmqMessageDeliveryQueue.Create(_retryQueuePath); MsmqMessageDeliveryQueue.Create(_failQueuePath); var binaryFormatter = new System.Messaging.BinaryMessageFormatter(); MsmqMessageDeliveryQueue testQueue = new MsmqMessageDeliveryQueue(_testQueuePath, binaryFormatter); MsmqMessageDeliveryQueue retryQueue = new MsmqMessageDeliveryQueue(_retryQueuePath, binaryFormatter); MsmqMessageDeliveryQueue failQueue = new MsmqMessageDeliveryQueue(_failQueuePath, binaryFormatter); return(new ServiceBusRuntime(new QueuedDeliveryCore(testQueue, retryQueue, failQueue))); }
public void MethodDispatcher_Publishes_Fault_Messages() { System.Messaging.IMessageFormatter binaryFormatter = new System.Messaging.BinaryMessageFormatter(); using (ServiceBusRuntime runtime = Create.BinaryMsmqRuntime()) { CEcho echo = new CEcho(); SubscriptionEndpoint replyEndpoint = new SubscriptionEndpoint(Guid.NewGuid(), "test", null, null, typeof(void), new MethodDispatcher(echo, false), new PredicateMessageFilter(m => { bool result = m.Action == "ThrowInvalidOperationException"; return result; })); runtime.Subscribe(replyEndpoint); runtime.Start(); try { string message = null; MessageDelivery[] output = runtime.PublishTwoWay(new PublishRequest(typeof(void), "ThrowInvalidOperationException", message), TimeSpan.FromSeconds(100)); Assert.IsNotNull(output); Assert.AreEqual(1, output.Length); Assert.IsInstanceOfType(typeof(InvalidOperationException), output[0].Message); } finally { runtime.Stop(); } } }
public void MethodDispatcher_Publishes_Fault_Messages() { System.Messaging.IMessageFormatter binaryFormatter = new System.Messaging.BinaryMessageFormatter(); using (ServiceBusRuntime runtime = Create.BinaryMsmqRuntime()) { CEcho echo = new CEcho(); SubscriptionEndpoint replyEndpoint = new SubscriptionEndpoint(Guid.NewGuid(), "test", null, null, typeof(void), new MethodDispatcher(echo, false), new PredicateMessageFilter(m => { bool result = m.Action == "ThrowInvalidOperationException"; return(result); })); runtime.Subscribe(replyEndpoint); runtime.Start(); try { string message = null; MessageDelivery[] output = runtime.PublishTwoWay(new PublishRequest(typeof(void), "ThrowInvalidOperationException", message), TimeSpan.FromSeconds(100)); Assert.IsNotNull(output); Assert.AreEqual(1, output.Length); Assert.IsInstanceOfType(typeof(InvalidOperationException), output[0].Message); } finally { runtime.Stop(); } } }
public void MethodDispatcher_Publishes_Response_Messages() { System.Messaging.IMessageFormatter binaryFormatter = new System.Messaging.BinaryMessageFormatter(); using (ServiceBusRuntime runtime = Create.BinaryMsmqRuntime()) { CEcho echo = new CEcho(); SubscriptionEndpoint replyEndpoint = new SubscriptionEndpoint(Guid.NewGuid(), "test", null, null, typeof(void), new MethodDispatcher(echo, false), new PredicateMessageFilter(m => m.Action == "Echo")); runtime.Subscribe(replyEndpoint); runtime.Start(); try { string message = "echo this"; MessageDelivery[] output = runtime.PublishTwoWay(new PublishRequest(typeof(void), "Echo", message), TimeSpan.FromSeconds(100)); Assert.IsNotNull(output); Assert.AreEqual(1, output.Length); Assert.AreEqual(message, (string)output[0].Message); } finally { runtime.Stop(); } } }
/// <summary> /// Fills a messages body or body stream, according to the on screen options. /// </summary> /// <param name="message">Message body.</param> private void FillMessageBody(System.Messaging.Message message) { //should we write directly to the body stream? if (optionsStreamDirectlyMenuItem.Checked) { if (textSourceRadioButton.Checked) { message.BodyStream = IOUtilities.StringToMemoryStream(textSourceTextBox.Text); } else { message.BodyStream = new FileStream(fileSourceTextBox.Text, FileMode.Open, FileAccess.Read); } } else { //set up the formatter System.Messaging.IMessageFormatter formatter; switch ((MessageFormatterType)formatterComboBoxItem.ComboBox.SelectedValue) { case MessageFormatterType.ActiveX: formatter = new System.Messaging.ActiveXMessageFormatter(); break; case MessageFormatterType.Binary: formatter = new System.Messaging.BinaryMessageFormatter(); break; case MessageFormatterType.Xml: default: formatter = new System.Messaging.XmlMessageFormatter(); break; } message.Formatter = formatter; //set up the body object body; if (textSourceRadioButton.Checked) { if (xmlCheckBox.Checked) { body = CreateXmlDocument(textSourceTextBox.Text); } else { body = textSourceTextBox.Text; } } else { using (StreamReader sr = new StreamReader(fileSourceTextBox.Text)) { body = sr.ReadToEnd(); } if (xmlCheckBox.Checked) { body = CreateXmlDocument(body.ToString()); } } message.Body = body; } }
/// <summary> /// Fills a messages body or body stream, according to the on screen options. /// </summary> /// <param name="message">Message body.</param> private void FillMessageBody(System.Messaging.Message message) { //should we write directly to the body stream? if (optionsStreamDirectlyMenuItem.Checked) { if (textSourceRadioButton.Checked) message.BodyStream = IOUtilities.StringToMemoryStream(textSourceTextBox.Text); else message.BodyStream = new FileStream(fileSourceTextBox.Text, FileMode.Open, FileAccess.Read); } else { //set up the formatter System.Messaging.IMessageFormatter formatter; switch ((MessageFormatterType)formatterComboBoxItem.ComboBox.SelectedValue) { case MessageFormatterType.ActiveX: formatter = new System.Messaging.ActiveXMessageFormatter(); break; case MessageFormatterType.Binary: formatter = new System.Messaging.BinaryMessageFormatter(); break; case MessageFormatterType.Xml: default: formatter = new System.Messaging.XmlMessageFormatter(); break; } message.Formatter = formatter; //set up the body object body; if (textSourceRadioButton.Checked) { if (xmlCheckBox.Checked) { body = CreateXmlDocument(textSourceTextBox.Text); } else body = textSourceTextBox.Text; } else { using (StreamReader sr = new StreamReader(fileSourceTextBox.Text)) { body = sr.ReadToEnd(); } if (xmlCheckBox.Checked) body = CreateXmlDocument(body.ToString()); } message.Body = body; } }
public void MethodDispatcher_Publishes_Response_Messages() { System.Messaging.IMessageFormatter binaryFormatter = new System.Messaging.BinaryMessageFormatter(); using (ServiceBusRuntime runtime = Create.BinaryMsmqRuntime()) { CEcho echo = new CEcho(); SubscriptionEndpoint replyEndpoint = new SubscriptionEndpoint(Guid.NewGuid(), "test", null, null, typeof(void), new MethodDispatcher(echo, false), new PredicateMessageFilter( m => m.Action == "Echo")); runtime.Subscribe(replyEndpoint); runtime.Start(); try { string message = "echo this"; MessageDelivery[] output = runtime.PublishTwoWay(new PublishRequest(typeof(void), "Echo", message), TimeSpan.FromSeconds(100)); Assert.IsNotNull(output); Assert.AreEqual(1, output.Length); Assert.AreEqual(message, (string)output[0].Message); } finally { runtime.Stop(); } } }