[zeromq-dev] PUB/SUB pattern support

Johnny Lee jlee at peaceatwork.org
Wed May 14 18:01:20 CEST 2014


Hello All,

I’m currently working on a suite of .NET applications, and I decided to go with ZeroMQ and the PUB/SUB pattern. Since this is my first time utilizing ZeroMQ, I would like to receive feedback from developers with a bit more experience.

The method I have included below creates the publisher and sends a serialized object when available. By the way, I have added a blocking call to the loop to prevent high CPU utilization. Thus far that change has made a world of difference.

Please let me know if you can spot any potential issues, or opportunities for improvement. 
We are also willing to contract for a few hours with someone versed in ZeroMQ to discuss the code below and the overall utilization of the program.


. . .


        public void StartSender(ZmqContext context)
        {
            if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                return;
            }


            string localIp = this.LocalIPAddress();


            //------------------------------------------------------------
            // Start Publisher
            //------------------------------------------------------------
            using (context)
            {
                using (this.ZmqPublisher = context.CreateSocket(ZeroMQ.SocketType.PUB))
                {
                    this.ZmqPublisher.Bind(string.Format("tcp://{0}:{1}", localIp,actPort));


                    while (true)
                    {
                        lock (this.Locker)
                        {
                            //-- Used with Monitor.Pulse(this.theApp.Locker)
                            //-- in Button class.
                            Monitor.Wait(this.Locker);


                            ResetSentIcon();


                            if (this.ObjAlert != null)
                            {  
                                this.ZmqPublisher.SendMore("B", Encoding.Unicode);
                                this.ZmqPublisher.Send(EpbSharedLib.Utilities.Serialization.SerializeObject(this.ObjAlert), Encoding.Unicode);
                                ELogger.Log(string.Format("Sending message '{0}'at {1}.", this.ObjAlert.AlertTitle, DateTime.Now)); 


                                this.ObjAlert = null;


                                SetSentIcon();
                            }
                        }
                    }
                }
            }
        }
. . .




 



 



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140514/6aee547f/attachment.htm>


More information about the zeromq-dev mailing list