Hi Carlos,
You should probably do a bit of background about this feature. This is the underlying primitive mechanism that the C# client uses:
Then you want to find out what to do. Redis PubSub is a non-durable real-time PubSub mechanism (i.e. if you're not listening you're going to lose messages).
When 1 Redis Client subscribes to a message it blocks the Redis Client at this point.
Console.WriteLine("Started Listening On '{0}'", ChannelName);
subscription.SubscribeToChannels(ChannelName); //blocking
So somewhere in another web server you are going to have another RedisClient that publishes a message to 'ChannelName':
using (var redisPublisher = new RedisClient(TestConfig.SingleHost))
{
redisPublisher.PublishMessage(ChannelName, message);
}
When that happens, any client 'subscribed or listening to that channel' will receive the message and fire off any callbacks:
subscription.OnMessage = (channel, msg) =>
{
Console.WriteLine("Received '{0}' from channel '{1}'", msg, channel);
//As soon as we've received all 5 messages, disconnect by unsubscribing to all channels
if (++messagesReceived == PublishMessageCount)
{
subscription.UnSubscribeFromAllChannels();
}
};
The 'subscribed' client will only stop blocking, i.e. allow the program flow to continue if they unsubscribe from all channels, e.g.
subscription.UnSubscribeFromAllChannels();
Anyway I hope this explains it better.
Cheers,
D