I am having a hard time separating the IRedisClient.PublishMessage
and IMessageQueueClient.Publish
and realize I must be mixing something up.
ServiceStack gives us the option to listen for pub/sub broadcasts like this:
static IRedisSubscription _subscription;
static IRedisClient redisClientSub;
static int received = 0;
static void ReadFromQueue()
{
redisClientSub = redisClientManager.GetClient();
_subscription = redisClientSub.CreateSubscription();
_subscription.OnMessage = (channel, msg) =>
{
try
{
received++;
}
catch (Exception ex)
{
}
};
Task.Run(() => _subscription.SubscribeToChannels("Test"));
}
Looks nice, straightforward. But what about the producer?
When looking at the classes available, I thought that one could either user the IRedisClient.PublishMessage(string toChannel, string message)
or IMessageQueueClient.Publish(string queueName, IMessage message)
.
string json = JsonConvert.SerializeObject(testReq);
redisClient.PublishMessage("Test", json);
// or:
myMessageQueueClient.Publish("Test", new Message<CoreEvent>(testReq));
In both cases, you specificy the channel name yourself. This is the behaviour I am seeing:
- the subscriber above only receives the message if I use
IRedisClient.PublishMessage(string toChannel, string message)
and never if I useIMessageQueueClient.Publish(string queueName, IMessage message)
- If I publish using
IRedisClient.PublishMessage
, I expected the “Test” channel to be populated (if I view with a Redis browser), but it is not. I never see any trace of the queue (lets say I dont start the subscription, but producers adds messages) - If I publish using
IMessageQueueClient.Publish(string queueName, IMessage message)
, the channel “Test” is created and the messages are persisted there, but never popped/fetched-and-deleted.
I need help in understanding the difference between the two. I have looked at source code and read all I can about it, but I haven’t found any documentation regarding IRedisClient.PublishMessage
.
Thanks!