Mercurial > silverbladetech
diff Messaging/Client/MainWindow.xaml.cs @ 29:9919ee227c93
msmq added
author | adminsh@apollo |
---|---|
date | Wed, 21 Mar 2012 22:09:18 +0000 |
parents | 4c0dea4760c5 |
children |
line wrap: on
line diff
--- a/Messaging/Client/MainWindow.xaml.cs Wed Mar 21 20:29:04 2012 +0000 +++ b/Messaging/Client/MainWindow.xaml.cs Wed Mar 21 22:09:18 2012 +0000 @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Messaging; using System.Text; +using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -20,6 +22,8 @@ /// </summary> public partial class MainWindow : Window { + public const int MessageCount = 10000; + public MainWindow() { InitializeComponent(); @@ -27,18 +31,51 @@ private void BtnRabbitClick(object sender, RoutedEventArgs e) { - Task - var cf = new ConnectionFactory {Address = "localhost:" + Settings.RabbitPortNumber}; + Task.Factory.StartNew(() => + { + var cf = new ConnectionFactory {Address = "localhost:" + Settings.RabbitPortNumber}; - using (var conn = cf.CreateConnection()) - using (var channel = conn.CreateModel()) + using (var conn = cf.CreateConnection()) + using (var channel = conn.CreateModel()) + { + for (var i = 0; i < MessageCount; i++) + { + channel.BasicPublish("amq.direct", Settings.RabbitQueueName, null, + Encoding.UTF8.GetBytes("hello from the client!")); + } + } + }); + } + + private void btnMsmq_Click(object sender, RoutedEventArgs e) + { + Task.Factory.StartNew(() => { - for (var i = 0; i < 10000; i++) + var msMq + = !MessageQueue.Exists(Settings.MsmqQueueName) + ? MessageQueue.Create(Settings.MsmqQueueName) + : new MessageQueue(Settings.MsmqQueueName); + + try { - channel.BasicPublish("amq.direct", Settings.QueueName, null, - Encoding.UTF8.GetBytes("hello from the client!")); + for (var i = 0; i < MessageCount; i++) + { + msMq.Send("Sending data to MSMQ at " + DateTime.Now.ToString()); + } + } + catch (MessageQueueException ee) + { + Console.Write(ee.ToString()); } - } + catch (Exception eee) + { + Console.Write(eee.ToString()); + } + finally + { + msMq.Close(); + } + }); } } } \ No newline at end of file