Mercurial > silverbladetech
comparison Messaging/Client/MainWindow.xaml.cs @ 29:9919ee227c93
msmq added
author | adminsh@apollo |
---|---|
date | Wed, 21 Mar 2012 22:09:18 +0000 |
parents | 4c0dea4760c5 |
children |
comparison
equal
deleted
inserted
replaced
28:4c0dea4760c5 | 29:9919ee227c93 |
---|---|
1 using System; | 1 using System; |
2 using System.Collections.Generic; | 2 using System.Collections.Generic; |
3 using System.Messaging; | |
3 using System.Text; | 4 using System.Text; |
5 using System.Threading.Tasks; | |
4 using System.Windows; | 6 using System.Windows; |
5 using System.Windows.Controls; | 7 using System.Windows.Controls; |
6 using System.Windows.Data; | 8 using System.Windows.Data; |
7 using System.Windows.Documents; | 9 using System.Windows.Documents; |
8 using System.Windows.Input; | 10 using System.Windows.Input; |
18 /// <summary> | 20 /// <summary> |
19 /// Interaction logic for MainWindow.xaml | 21 /// Interaction logic for MainWindow.xaml |
20 /// </summary> | 22 /// </summary> |
21 public partial class MainWindow : Window | 23 public partial class MainWindow : Window |
22 { | 24 { |
25 public const int MessageCount = 10000; | |
26 | |
23 public MainWindow() | 27 public MainWindow() |
24 { | 28 { |
25 InitializeComponent(); | 29 InitializeComponent(); |
26 } | 30 } |
27 | 31 |
28 private void BtnRabbitClick(object sender, RoutedEventArgs e) | 32 private void BtnRabbitClick(object sender, RoutedEventArgs e) |
29 { | 33 { |
30 Task | 34 Task.Factory.StartNew(() => |
31 var cf = new ConnectionFactory {Address = "localhost:" + Settings.RabbitPortNumber}; | 35 { |
36 var cf = new ConnectionFactory {Address = "localhost:" + Settings.RabbitPortNumber}; | |
32 | 37 |
33 using (var conn = cf.CreateConnection()) | 38 using (var conn = cf.CreateConnection()) |
34 using (var channel = conn.CreateModel()) | 39 using (var channel = conn.CreateModel()) |
40 { | |
41 for (var i = 0; i < MessageCount; i++) | |
42 { | |
43 channel.BasicPublish("amq.direct", Settings.RabbitQueueName, null, | |
44 Encoding.UTF8.GetBytes("hello from the client!")); | |
45 } | |
46 } | |
47 }); | |
48 } | |
49 | |
50 private void btnMsmq_Click(object sender, RoutedEventArgs e) | |
51 { | |
52 Task.Factory.StartNew(() => | |
35 { | 53 { |
36 for (var i = 0; i < 10000; i++) | 54 var msMq |
55 = !MessageQueue.Exists(Settings.MsmqQueueName) | |
56 ? MessageQueue.Create(Settings.MsmqQueueName) | |
57 : new MessageQueue(Settings.MsmqQueueName); | |
58 | |
59 try | |
37 { | 60 { |
38 channel.BasicPublish("amq.direct", Settings.QueueName, null, | 61 for (var i = 0; i < MessageCount; i++) |
39 Encoding.UTF8.GetBytes("hello from the client!")); | 62 { |
63 msMq.Send("Sending data to MSMQ at " + DateTime.Now.ToString()); | |
64 } | |
40 } | 65 } |
41 } | 66 catch (MessageQueueException ee) |
67 { | |
68 Console.Write(ee.ToString()); | |
69 } | |
70 catch (Exception eee) | |
71 { | |
72 Console.Write(eee.ToString()); | |
73 } | |
74 finally | |
75 { | |
76 msMq.Close(); | |
77 } | |
78 }); | |
42 } | 79 } |
43 } | 80 } |
44 } | 81 } |