-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathProgram.cs
151 lines (126 loc) · 5.48 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Threading;
using MessageQueue.Core.Services;
using MessageQueue.Log.NLog.Concrete;
using MessageQueue.CofigurationProvider.AppSettings.Concrete;
namespace MessageQueue.Sender
{
class Program
{
#region Private Data Members
private const ushort messageCount = 25;
private const ushort delayBetweenMessagesInMs = 200;
#endregion
static void Main(string[] args)
{
Console.WriteLine("Please select the Message Queue (Sender):" + Environment.NewLine + "1- ZeroMq" + Environment.NewLine + "2- RabbitMq" + Environment.NewLine + "3- ServiceBus");
var option = Console.ReadKey();
switch (option.Key)
{
case ConsoleKey.D1:
case ConsoleKey.NumPad1:
Test_ZeroMqFaF_Send();
break;
case ConsoleKey.D2:
case ConsoleKey.NumPad2:
Test_RabbitMqFaF_Send();
break;
case ConsoleKey.D3:
case ConsoleKey.NumPad3:
Test_ServiceBusFaF_Send();
break;
default:
Test_ZeroMqFaF_Send();
break;
}
Console.ReadKey();
}
#region ZeroMq
public static async void Test_ZeroMqFaF_Send()
{
try
{
Console.WriteLine();
Console.WriteLine("ZeroMq test outbound messages... (press any key to start sending)");
Console.ReadKey();
Console.WriteLine("Started (message count: {0})....", messageCount);
using (var outboundMessageQueue = MessagingQueueFactory.CreateOutboundFaF<string>(new AppSettingsConfigurationProvider(), "ZeroMqFaFOutbound", new NQueueLogger("Default")))
{
for (int i = 0; i < messageCount; i++)
{
var message = $"This is FAF message number: {i} (sent at: {DateTime.Now.ToLongTimeString()})";
Console.WriteLine("Pushing: " + Environment.NewLine + message);
outboundMessageQueue.SendMessage(message);
//await outboundMessageQueue.SendMessageAsync(message);
Console.WriteLine("Pushed successfully..." + Environment.NewLine);
// Adding delay.
Thread.Sleep(delayBetweenMessagesInMs);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
#endregion
#region RabbitMq
public static async void Test_RabbitMqFaF_Send()
{
try
{
Console.WriteLine();
Console.WriteLine("RabbitMq test outbound messages (press any key to start sending)...");
Console.ReadKey();
Console.WriteLine("Started (message count: {0})....", messageCount);
// Creating queue object from factory.
using (var outboundMessageQueue = MessagingQueueFactory.CreateOutboundFaF<string>(new AppSettingsConfigurationProvider(), "RabbitMqFaFOutbound", new NQueueLogger("Default")))
{
for (int i = 0; i < messageCount; i++)
{
var message = $"This is FAF message number: {i} (sent at: {DateTime.Now.ToLongTimeString()})";
Console.WriteLine("Pushing: " + Environment.NewLine + message);
outboundMessageQueue.SendMessage(message);
//await outboundMessageQueue.SendMessageAsync(message);
Console.WriteLine("Pushed successfully..." + Environment.NewLine);
Thread.Sleep(delayBetweenMessagesInMs);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
#endregion
#region ServiceBus
public static async void Test_ServiceBusFaF_Send()
{
try
{
Console.WriteLine();
Console.WriteLine("ServiceBus test outbound messages (press any key to start sending)...");
Console.ReadKey();
Console.WriteLine("Started (message count: {0})....", messageCount);
// Creating queue object from factory.
using (var outboundMessageQueue = MessagingQueueFactory.CreateOutboundFaF<string>(new AppSettingsConfigurationProvider(), "ServiceBusFaFOutbound", new NQueueLogger("Default")))
{
for (int i = 0; i < messageCount; i++)
{
var message = $"This is FAF message number: {i} (sent at: {DateTime.Now.ToLongTimeString()})";
Console.WriteLine("Pushing: " + Environment.NewLine + message);
outboundMessageQueue.SendMessage(message);
//await outboundMessageQueue.SendMessageAsync(message);
Console.WriteLine("Pushed successfully..." + Environment.NewLine);
Thread.Sleep(delayBetweenMessagesInMs);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
#endregion
}
}