public void Simplest_Test_Publisher_To_Subscriber() { NUnitUtils.PrintTestName(); var sw = Stopwatch.StartNew(); var cd = new CountdownEvent(5); { var freePort = NUnitUtils.TcpPortFree(); var publisher = new PublisherNetMq <int>("tcp://127.0.0.1:" + freePort, loggerDelegate: Console.Write); var subscriber = new SubscriberNetMq <int>("tcp://127.0.0.1:" + freePort, loggerDelegate: Console.Write); subscriber.Subscribe(o => { Console.Write("Test 1: {0}\n", o); cd.Signal(); }, ex => { Console.WriteLine("Exception! {0}", ex.Message); }); publisher.OnNext(38); publisher.OnNext(39); publisher.OnNext(40); publisher.OnNext(41); publisher.OnNext(42); } if (cd.Wait(GlobalTimeout.Timeout) == false) // Blocks until _countdown.Signal has been called. { Assert.Fail("Timed out, this test should complete in {0} seconds.", GlobalTimeout.Timeout.TotalSeconds); } NUnitUtils.PrintElapsedTime(sw.Elapsed); }
private static void Main() { var publisher = new PublisherNetMq <int>("tcp://127.0.0.1:56001"); while (true) { publisher.OnNext(42); // Sends 42. } // ReSharper disable once FunctionNeverReturns }
public static void Speed_Test_Publisher_Subscriber() { NUnitUtils.PrintTestName(); var sw = Stopwatch.StartNew(); { var max = 100 * 1000; var cd = new CountdownEvent(max); var receivedNum = 0; { Console.Write("Speed test with {0} messages:\n", max); var freePort = NUnitUtils.TcpPortFree(); var publisher = new PublisherNetMq <int>("tcp://127.0.0.1:" + freePort, loggerDelegate: Console.Write); var subscriber = new SubscriberNetMq <int>("tcp://127.0.0.1:" + freePort, loggerDelegate: Console.Write); subscriber.Subscribe(i => { receivedNum++; cd.Signal(); if (i % 10000 == 0) { //Console.Write("*"); } }); sw.Start(); for (var i = 0; i < max; i++) { publisher.OnNext(i); } } if (cd.Wait(GlobalTimeout.Timeout) == false) // Blocks until _countdown.Signal has been called. { Assert.Fail("\nTimed out, this test should complete in {0} seconds. receivedNum={1}", GlobalTimeout.Timeout.TotalSeconds, receivedNum); } // On my machine, achieved >120,000 messages per second. NUnitUtils.PrintElapsedTime(sw.Elapsed, max); } }
static void Main(string[] args) { Console.Write("Reactive Extensions publisher demo:\n"); string endPoint = "tcp://127.0.0.1:56001"; if (args.Length >= 1) { endPoint = args[0]; } Console.Write("Endpoint: {0}\n", endPoint); // Debug: Subscribe to ourself. { var subscriber = new SubscriberNetMq <MyMessage>(endPoint, new SerializeViaProtoBuf <MyMessage>(), loggerDelegate: msg => Console.Write(msg)); // Debug: subscribe to ourself. If you run the "SampleSubscriber" project now, you will see the same // messages appearing in that subscriber too. subscriber.Subscribe(message => { Console.Write("Received: {0}, '{1}'.\n", message.Num, message.Name); }); } // Publisher. { var publisher = new PublisherNetMq <MyMessage>(endPoint, new SerializeViaProtoBuf <MyMessage>(), loggerDelegate: msg => Console.Write(msg)); int i = 0; while (true) { var message = new MyMessage(i, "Bob"); // When we call "OnNext", it binds a publisher to this endpoint endpoint. publisher.OnNext(message); Console.Write("Published: {0}, '{1}'.\n", message.Num, message.Name); Thread.Sleep(TimeSpan.FromMilliseconds(1000)); i++; } } // NOTE: If you run the "SampleSubscriber" project now, you will see the same messages appearing in the subscriber. }
static void Main(string[] args) { Console.Write("Reactive Extensions publisher demo:\n"); string endPoint = "tcp://127.0.0.1:56001"; if (args.Length >= 1) { endPoint = args[0]; } Console.Write("Endpoint: {0}\n", endPoint); // Debug: Subscribe to ourself. { var subscriber = new SubscriberNetMq<MyMessage>(endPoint, loggerDelegate: msg => Console.Write(msg)); // Debug: subscribe to ourself. If you run the "SampleSubscriber" project now, you will see the same // messages appearing in that subscriber too. subscriber.Subscribe(message => { Console.Write("Received: {0}, '{1}'.\n", message.Num, message.Name); }); } // Publisher. { var publisher = new PublisherNetMq<MyMessage>(endPoint, loggerDelegate: msg => Console.Write(msg)); int i = 0; while (true) { var message = new MyMessage(i, "Bob"); // When we call "OnNext", it binds a publisher to this endpoint endpoint. publisher.OnNext(message); Console.Write("Published: {0}, '{1}'.\n", message.Num, message.Name); Thread.Sleep(TimeSpan.FromMilliseconds(1000)); i++; } } // NOTE: If you run the "SampleSubscriber" project now, you will see the same messages appearing in the subscriber. }
public void Simplest_Test_Publisher_To_Subscriber() { NUnitUtils.PrintTestName(); var sw = Stopwatch.StartNew(); var cd = new CountdownEvent(5); { var freePort = NUnitUtils.TcpPortFree(); var publisher = new PublisherNetMq<int>("tcp://127.0.0.1:" + freePort, loggerDelegate: Console.Write); var subscriber = new SubscriberNetMq<int>("tcp://127.0.0.1:" + freePort, loggerDelegate: Console.Write); subscriber.Subscribe(o => { Console.Write("Test 1: {0}\n", o); cd.Signal(); }, ex => { Console.WriteLine("Exception! {0}", ex.Message); }); publisher.OnNext(38); publisher.OnNext(39); publisher.OnNext(40); publisher.OnNext(41); publisher.OnNext(42); } if (cd.Wait(GlobalTimeout.Timeout) == false) // Blocks until _countdown.Signal has been called. { Assert.Fail("Timed out, this test should complete in {0} seconds.", GlobalTimeout.Timeout.TotalSeconds); } NUnitUtils.PrintElapsedTime(sw.Elapsed); }
public static void Speed_Test_Publisher_Subscriber() { NUnitUtils.PrintTestName(); var sw = Stopwatch.StartNew(); { var max = 100*1000; var cd = new CountdownEvent(max); var receivedNum = 0; { Console.Write("Speed test with {0} messages:\n", max); var freePort = NUnitUtils.TcpPortFree(); var publisher = new PublisherNetMq<int>("tcp://127.0.0.1:" + freePort, loggerDelegate: Console.Write); var subscriber = new SubscriberNetMq<int>("tcp://127.0.0.1:" + freePort, loggerDelegate: Console.Write); subscriber.Subscribe(i => { receivedNum++; cd.Signal(); if (i%10000 == 0) { //Console.Write("*"); } }); sw.Start(); for (var i = 0; i < max; i++) { publisher.OnNext(i); } } if (cd.Wait(GlobalTimeout.Timeout) == false) // Blocks until _countdown.Signal has been called. { Assert.Fail("\nTimed out, this test should complete in {0} seconds. receivedNum={1}", GlobalTimeout.Timeout.TotalSeconds, receivedNum); } // On my machine, achieved >120,000 messages per second. NUnitUtils.PrintElapsedTime(sw.Elapsed, max); } }