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]);
}
}