0

I am currently using Redis version 2.6.12 and 2.4.5 for windows port version for some performance analysis. I have written a pub/sub application which I have a window service acting as a subscriber. and another windows form acting as Publisher.

I have noticed that after sending around 50++ consecutive messages from the publisher. The subscriber stops responding to new messages. There is no exception thrown from the publisher side.

Same behaviour occurred on both version of Redis.

Has anyone experienced this kind of weird behaviour?

This is the code from my windows form (publisher):

using (var redisPublisher = new RedisClient())
{
    var message = new LastTrainProcessedMessage(DateTime.Now, "TEST", SystemMonitorStatus.Normal, 10);
    label1.Text += (String.Format(@"Publishing '{0}' to '{1}'", message.ToString(), ChannelName)) + Environment.NewLine;                
    redisPublisher.PublishMessage(ChannelName, ServiceStack.Text.JsonSerializer.SerializeToString(message, typeof(LastTrainProcessedMessage)));
}

This is the code from my Subscriber:

using (_redisConsumer = new RedisClient("localhost"))            
    using (_subscription = _redisConsumer.CreateSubscription())
    {
        try
        {
             _subscription.OnSubscribe = channel => _logger.Info(string.Format("Subscribed to '{0}'", channel));
              _subscription.OnUnSubscribe = channel => _logger.Info(string.Format("UnSubscribed from '{0}'", channel));                    
              _subscription.OnMessage = (channel, msg) =>
              {
                  _logger.Info(string.Format("Received '{0}' from channel '{1}'", msg, channel));
                  var ltpm = JsonSerializer.DeserializeFromString<LastTrainProcessedMessage>(msg);

                  //persist to redis and trigger SignalR call...
                  _smState.UpdateLastTrainProcessedState(ltpm.ReadingTimestamp, ltpm.Location, SystemMonitorStatus.Normal);
                  _smState.AddAlerts(ltpm.NumberOfAlerts);                      
              };                    
              _logger.Info(string.Format("Started Listening On '{0}'", _channelName));
              _subscription.SubscribeToChannels(_channelName); //blocking
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }
        }

Thanks.

4

1 回答 1

0

您是否尝试使用以下命令打开终端: redis-cli psubscribe "*" 以查看即使订阅者挂起,您的消息是否仍在发送?

问题似乎肯定来自onMessage侦听器内部,删除以下行:

_subscription.UnSubscribeFromChannels(_channelName);
_subscription.SubscribeToChannels(_channelName);

它应该可以工作。

于 2013-11-01T10:39:07.467 回答