private static void PubClient(bool useNetMQ)
        {
            int  msgCount = 10;
            Guid clientId = Guid.NewGuid();

            var messagesToSend   = new Queue <CommonRequest>();
            var receivedMessages = new List <int>();

            for (int i = 0; i < msgCount; i++)
            {
                messagesToSend.Enqueue(new CommonRequest
                {
                    ClientId  = clientId,
                    RequestId = i,
                    Topic     = i % 2 == 0 ? "ABBA" : "ACDC",
                    Message   = "Hello: " + i,
                    Duration  = 5000
                });
            }

            Console.WriteLine("Client {0}", clientId.ToString().Substring(30));

            IPub <CommonRequest> pub = null;

            if (useNetMQ)
            {
                pub = new Common.NetMQ.Pub <CommonRequest>("tcp://127.0.0.1:5020");
            }
            else
            {
                pub = new Common.clrzmq.Pub <CommonRequest>("tcp://127.0.0.1:5020");
            }

            pub.Start();

            var senderTask = Task.Factory.StartNew(() =>
            {
                while (messagesToSend.Count > 0)
                {
                    Thread.Sleep(2000);
                    var msg = messagesToSend.Dequeue();
                    Console.WriteLine("Sending {0}", msg.RequestId.ToString());
                    pub.AddMessage(msg);
                }
            });

            Task.WaitAll(senderTask);
        }
示例#2
0
 public PubQueue(IPub pub)
 {
     this.pub = pub;
     SetEnable(true);
 }
示例#3
0
 public static IPubQueue AddPubQueue(this IPub pub) => new PubQueue(pub);