NetMQ multiple publishers

1.2k views Asked by At

I am running a pub-sub set-up that works very well for a single publisher and multiple subscribers.

But I now wish to have several publishers publishing to the same "Channel", when I try this, the second time I try to Bind I get an address-already-used error.

Why can't I have a second publisher?

This is for a high-throughput application approx 250K messages/sec and a quick read of xPub-xSub suggests an intermediary will add overhead.

   private void BackgroundProcess()
    {
        int msgSeqNum = 0;
        using (var server = new PublisherSocket())
        {
            server.Options.SendHighWatermark = 1000;
            server.Bind(Connection);


            var address = Key;
            string txt;
            while (true)
            {

                if (O.TryTake(out txt, 60000))
                {
                    msgSeqNum++;
                    server.SendMoreFrame(address).SendMoreFrame(msgSeqNum.ToString()).SendMoreFrame(DateTime.UtcNow.ToString("yyyyMMddTHHmmssffffff")).SendFrame("Whatever");
                }

            }

        }
    }
1

There are 1 answers

0
Robbert Draaisma On

Netmq either works with a one on one socket set or a one to many socket set. You are getting close, you will need the xpub xsub to work as a proxy netmq actually provides one for this purpose.

https://netmq.readthedocs.io/en/latest/xpub-xsub/

As for why, this is a limitation of the underlying tcp layer, you can’t bind multiple tcp listeners to a single port afaik