forked from booksbyus/zguide
-
Notifications
You must be signed in to change notification settings - Fork 23
/
pathopub.cs
66 lines (59 loc) · 1.55 KB
/
pathopub.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using ZeroMQ;
namespace Examples
{
static partial class Program
{
public static void PathoPub(string[] args)
{
//
// Pathological publisher
// Sends out 1,000 topics and then one random update per second
//
// Author: metadings
//
if (args == null || args.Length < 1)
{
Console.WriteLine();
Console.WriteLine("Usage: ./{0} PathoPub [Endpoint]", AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine();
Console.WriteLine(" Endpoint Where PathoPub should connect to.");
Console.WriteLine(" Default is null, Binding on tcp://*:5556");
Console.WriteLine();
args = new string[] { null };
}
using (var context = new ZContext())
using (var publisher = new ZSocket(context, ZSocketType.PUB))
{
if (args[0] != null)
{
publisher.Connect(args[0]);
}
else
{
publisher.Bind("tcp://*:5556");
}
// Ensure subscriber connection has time to complete
Thread.Sleep(100);
// Send out all 1,000 topic messages
for (int topic = 0; topic < 1000; ++topic)
{
publisher.SendMore(new ZFrame(string.Format("{0:D3}", topic)));
publisher.Send(new ZFrame("Save Roger"));
}
// Send one random update per second
var rnd = new Random();
while (true)
{
Thread.Sleep(10);
publisher.SendMore(new ZFrame(string.Format("{0:D3}", rnd.Next(1000))));
publisher.Send(new ZFrame("Off with his head!"));
}
}
}
}
}