0
votes

I was wondering if there is a way to raise events on new subscription to a publisher socket

For example:

        PublisherSocket publisher = new PublisherSocket();

        publisher.Bind("tcp://*:5555");

        NetMQPoller poller = new NetMQPoller { publisher };
        poller.RunAsync();

        poller.OnSubscription += topic =>
        {
            AddToPool(topic);
        };

        Task.Factory.StartNew(() =>
        {
            SubscriberSocket sub = new SubscriberSocket();
            sub.Connect("tcp://127.0.0.1:5555");

            Thread.Sleep(1000);
            sub.Subscribe("A");
        }, TaskCreationOptions.LongRunning);

        publisher.ReceiveReady += Publisher_ReceiveReady;

Of course, OnSubscription doesn't really exist, but I was wondering if there is any way around it.

I need my server to be aware of all the subscriptions.

I though about two ways to implement it:

  1. Create an additional router socket in the server, all subscriptions will be sent both to the publisher socket and to the router socket (unsubscriptions as well). This will allow me to poll the subscriptions from the router.

  2. Not use publisher/subscriber at all, create all the pubsub mechanism with router/dealer.

What would you suggest me do?

1
As written in the zeroMQ guide it is not possible to track subscriptions, but having a look at Advanced Pub-Sub-Pattern you will find a Reliable-Pub-Sub (Clone) Pattern, that is using a second ROUTER/DEALER socket to achieve what you wantdwonisch

1 Answers

1
votes

If you use an XPUB rather than PUB socket you can receive the subscription messages as you would regular messages on any other socket type.