26
|
1 using System;
|
|
2 using System.Collections.Generic;
|
29
|
3 using System.Messaging;
|
26
|
4 using System.Text;
|
29
|
5 using System.Threading.Tasks;
|
26
|
6 using System.Windows;
|
|
7 using System.Windows.Controls;
|
|
8 using System.Windows.Data;
|
|
9 using System.Windows.Documents;
|
|
10 using System.Windows.Input;
|
|
11 using System.Windows.Media;
|
|
12 using System.Windows.Media.Imaging;
|
|
13 using System.Windows.Navigation;
|
|
14 using System.Windows.Shapes;
|
28
|
15 using Common;
|
|
16 using RabbitMQ.Client;
|
26
|
17
|
|
18 namespace Client
|
|
19 {
|
|
20 /// <summary>
|
|
21 /// Interaction logic for MainWindow.xaml
|
|
22 /// </summary>
|
|
23 public partial class MainWindow : Window
|
|
24 {
|
29
|
25 public const int MessageCount = 10000;
|
|
26
|
26
|
27 public MainWindow()
|
|
28 {
|
|
29 InitializeComponent();
|
|
30 }
|
28
|
31
|
|
32 private void BtnRabbitClick(object sender, RoutedEventArgs e)
|
|
33 {
|
29
|
34 Task.Factory.StartNew(() =>
|
|
35 {
|
|
36 var cf = new ConnectionFactory {Address = "localhost:" + Settings.RabbitPortNumber};
|
28
|
37
|
29
|
38 using (var conn = cf.CreateConnection())
|
|
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(() =>
|
28
|
53 {
|
29
|
54 var msMq
|
|
55 = !MessageQueue.Exists(Settings.MsmqQueueName)
|
|
56 ? MessageQueue.Create(Settings.MsmqQueueName)
|
|
57 : new MessageQueue(Settings.MsmqQueueName);
|
|
58
|
|
59 try
|
28
|
60 {
|
29
|
61 for (var i = 0; i < MessageCount; i++)
|
|
62 {
|
|
63 msMq.Send("Sending data to MSMQ at " + DateTime.Now.ToString());
|
|
64 }
|
|
65 }
|
|
66 catch (MessageQueueException ee)
|
|
67 {
|
|
68 Console.Write(ee.ToString());
|
28
|
69 }
|
29
|
70 catch (Exception eee)
|
|
71 {
|
|
72 Console.Write(eee.ToString());
|
|
73 }
|
|
74 finally
|
|
75 {
|
|
76 msMq.Close();
|
|
77 }
|
|
78 });
|
28
|
79 }
|
26
|
80 }
|
28
|
81 } |