-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathProgram.cs
128 lines (108 loc) · 4.87 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Threading;
using MessageQueue.Core.Services;
using MessageQueue.Log.NLog.Concrete;
using MessageQueue.CofigurationProvider.AppSettings.Concrete;
namespace MessageQueue.RaR.Client
{
class Program
{
#region Private Data Members
private const int messageCount = 10;
private static int clientNumber;
private static int gapeBetweenMessagesInMs = 0;
#endregion
static void Main(string[] args)
{
// Setting random gape time between messages.
var randomeNumberGenerator = new Random();
gapeBetweenMessagesInMs = randomeNumberGenerator.Next(1, 1000) > 500 ? 100 : 200;
// Setting client number.
var rnd = new Random();
clientNumber = rnd.Next(1, 10000);
Console.WriteLine("Please select the Message Queue (Client):" + Environment.NewLine + "1- ZeroMq" + Environment.NewLine + "2- RabbitMq");
var option = Console.ReadKey();
switch (option.Key)
{
case ConsoleKey.D1:
case ConsoleKey.NumPad1:
Test_ZeroMqRaR_Request();
break;
case ConsoleKey.D2:
case ConsoleKey.NumPad2:
Test_RabbitMqRaR_Request();
break;
default:
Test_ZeroMqRaR_Request();
break;
}
Console.ReadKey();
}
#region ZeroMq
public static void Test_ZeroMqRaR_Request()
{
try
{
Console.WriteLine();
Console.WriteLine("ZeroMq test outbound messages (client)... (press any key to start sending)");
Console.ReadKey();
Console.WriteLine("Started (client Id: {0}, message count: {1}, gape between messages: {2}ms)....", clientNumber, messageCount, gapeBetweenMessagesInMs);
// Creating queue object from factory.
var outboundMessageQueue = MessagingQueueFactory.CreateOutboundRaR<string, string>(new AppSettingsConfigurationProvider(), "ZeroMqRaRClient", new NQueueLogger("Default"));
outboundMessageQueue.OnResponseReady += ZeroMqOutboundMessageQueue_OnResponseReady;
for (int i = 1; i <= messageCount; i++)
{
var message = string.Format("RAR message number: {0} client {1} (sent at: {2})", i,
clientNumber, DateTime.Now.ToLongTimeString());
Console.WriteLine("Requesting: " + Environment.NewLine + message);
outboundMessageQueue.SendRequest(message);
Thread.Sleep(gapeBetweenMessagesInMs);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
private static void ZeroMqOutboundMessageQueue_OnResponseReady(string responseData)
{
Console.WriteLine("Reply from server:" + Environment.NewLine + responseData);
Console.WriteLine("------------------------------");
}
#endregion
#region RabbitMq
public static void Test_RabbitMqRaR_Request()
{
try
{
Console.WriteLine();
Console.WriteLine("RabbitMq test outbound messages (client)... (press any key to start sending)");
Console.ReadKey();
Console.WriteLine("Started (client Id: {0}, message count: {1}, gape between messages: {2}ms)....",
clientNumber, messageCount, gapeBetweenMessagesInMs);
// Creating queue object from factory.
var outboundMessageQueue = MessagingQueueFactory.CreateOutboundRaR<string, string>(new AppSettingsConfigurationProvider(),
"RabbitMqRaRClient", new NQueueLogger("Default"));
outboundMessageQueue.OnResponseReady += RabbitMqOutboundMessageQueue_OnResponseReady;
for (int i = 1; i <= messageCount; i++)
{
var message = string.Format("RAR message number: {0} client {1} (sent at: {2})", i, clientNumber,
DateTime.Now.ToLongTimeString());
Console.WriteLine("Requesting: " + Environment.NewLine + message);
outboundMessageQueue.SendRequest(message);
Thread.Sleep(gapeBetweenMessagesInMs);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
private static void RabbitMqOutboundMessageQueue_OnResponseReady(string responseData)
{
Console.WriteLine("Reply from server:" + Environment.NewLine + responseData);
Console.WriteLine("------------------------------");
}
#endregion
}
}