This repository was archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 860
Expand file tree
/
Copy pathProgram2.cs
More file actions
80 lines (67 loc) · 2.36 KB
/
Program2.cs
File metadata and controls
80 lines (67 loc) · 2.36 KB
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
using System;
using System.Diagnostics;
using System.Threading;
using ServiceStack.Redis;
using ServiceStack.Redis.Messaging;
using ServiceStack.Text;
namespace TestMqHost
{
class Program2
{
static void Main(string[] args)
{
var clientManager = new PooledRedisClientManager(new[] { "localhost" })
{
PoolTimeout = 1000,
};
using (var client = clientManager.GetClient())
{
client.FlushAll();
}
var mqHost = new RedisMqServer(clientManager);
var msgsProcessed = 0;
var msgsQueued = 0;
var sum = 0;
mqHost.RegisterHandler<Incr>(c =>
{
var dto = c.GetBody();
sum += dto.Value;
Console.WriteLine("Received {0}, sum: {1}", dto.Value, sum);
msgsProcessed++;
return null;
});
mqHost.Start();
var processes = Process.GetProcessesByName("redis-server");
var timer = new Timer(s =>
{
using (var client = mqHost.MessageFactory.CreateMessageProducer())
{
try
{
client.Publish(new Incr { Value = 1 });
msgsQueued++;
Console.WriteLine("Message #{0} published.", msgsQueued);
}
catch { }
}
}, null, TimeSpan.Zero, TimeSpan.FromSeconds(1));
Thread.Sleep(5000);
timer.Change(Timeout.Infinite, Timeout.Infinite);
Thread.Sleep(1000);
int msgsQueuedBeforeKill = msgsQueued;
int msgsProcessedBeforeKill = msgsProcessed;
processes[0].Kill();
timer.Change(TimeSpan.Zero, TimeSpan.FromSeconds(1));
Thread.Sleep(15000);
timer.Dispose();
Thread.Sleep(1000);
mqHost.GetStats().PrintDump();
mqHost.GetStatus().Print();
"Messages queued before kill: {0}".Print(msgsQueuedBeforeKill);
"Messages processed before kill: {0}".Print(msgsProcessedBeforeKill);
"Messages queued: {0}".Print(msgsQueued);
"Messages processed: {0}".Print(msgsProcessed);
Console.ReadKey();
}
}
}