public void TestPush() { string address = string.Format("tcp://localhost:22245"); using (var acceptor = new NetMqPushAcceptor(address)) using (var pusher = new NetMqPusher(address)) using (var countDown = new CountdownEvent(2)) { acceptor.Start(); acceptor.Subscribe("test", m => { if (!countDown.IsSet) { countDown.Signal(); } }); pusher.Start(); Task.Run(() => { while (!countDown.IsSet) { pusher.Publish("test", new byte[] { 1, 2, 3 }); Thread.Sleep(100); } }); Assert.IsTrue(countDown.Wait(5000)); } }
private static void Main(string[] args) { string address = ConfigurationManager.AppSettings["GatewayServerAddress"]; var pusher = new NetMqPusher(address); pusher.Start(); for (int i = 0; i < 100; i++) { int i1 = i; Task.Factory.StartNew(() => { int a = i1; int b = i1; while (true) { Thread.Sleep(100); try { var q = new Quote { InstrumentId = (ushort)(313 * i1), Bid = a++, Ask = b++, TradeTime = DateTime.Now, LastUpdate = DateTime.Now }; pusher.Publish("q", q, BinarySerializer <Quote> .SerializeToByteArray); } catch (Exception ex) { Thread.Sleep(1000); } } }, TaskCreationOptions.LongRunning); } Console.ReadKey(); }
private static void Main(string[] args) { string address = ConfigurationManager.AppSettings["GatewayServerAddress"]; var pusher = new NetMqPusher(address); pusher.Start(); for (int i = 0; i < 100; i++) { int i1 = i; Task.Factory.StartNew(() => { int a = i1; int b = i1; while (true) { Thread.Sleep(100); try { var q = new Quote { InstrumentId = (ushort) (313*i1), Bid = a++, Ask = b++, TradeTime = DateTime.Now, LastUpdate = DateTime.Now }; pusher.Publish("q", q, BinarySerializer<Quote>.SerializeToByteArray); } catch (Exception ex) { Thread.Sleep(1000); } } }, TaskCreationOptions.LongRunning); } Console.ReadKey(); }
public void TestPush() { string address = string.Format("tcp://localhost:22245"); using (var acceptor = new NetMqPushAcceptor(address)) using (var pusher = new NetMqPusher(address)) using (var countDown = new CountdownEvent(2)) { acceptor.Start(); acceptor.Subscribe("test", m => { if (!countDown.IsSet) countDown.Signal(); }); pusher.Start(); Task.Run(() => { while (!countDown.IsSet) { pusher.Publish("test", new byte[] {1, 2, 3}); Thread.Sleep(100); } }); Assert.IsTrue(countDown.Wait(5000)); } }