0

Using NetMQ (port from ZeroMQ) with C#.

The publisher and subscriber live on different web services.

At an underdetermined time, a publisher will broadcast a message to all subscribers.

If the web service which holds the publisher goes down, how can the subscriber know about that?

I am trying to avoid using a polling mechanism to solve this problem e.g. broadcast a message every x seconds, if subscriber doesn't get a message in x seconds, you may assume that server is down.

Example Publisher:

    private PublisherSocket _publisherSocket;

    public void StartPublisher()
    {
        _publisherSocket = new PublisherSocket();

        _publisherSocket.Bind("tcp://localhost:1234");

    }

    public void SendMessage(string message)
    {
        _publisherSocket
            .SendMoreFrame("superMessage")
            .SendFrame(message);
    }

Example Subscriber:

    public void StartSubscriber()
    {
        _subscriberSocket.Connect("tcp://localhost:1234");
        _subscriberSocket.Subscribe("superMessage");

        while (_subscriberIsActive)
        {
            // Blocks until a message is received
            var messages = _subscriberSocket.ReceiveMultipartStrings();

            Console.WriteLine(messages[1]);
        }
    }
GIVE-ME-CHICKEN
  • 1,239
  • 3
  • 15
  • 29
  • 1
    I believe that there is no methods to solve this without polling. Even if some solution will have high-level API made in non-polling style, then anyway internally it will use polling or rely or some low-level API, which use polling. – Serg Feb 24 '21 at 09:21
  • @Serg - That's what I was running into. I just picked up this library recently and just thought I may be missing something. System.Net.Sockets.TcpClient.Connected is able to determine whether the client is still connected to the remote host, I guess I was hoping for something similar with this library. – GIVE-ME-CHICKEN Feb 24 '21 at 09:27
  • 2
    of course the subscriber can not know if the publisher is dead or just not sending, without asking. Use a second socket to communicate status info. (zmqsockets are cheap) – Alex Feb 28 '21 at 13:34

0 Answers0