我目前正在使用Redis版本2.6.12和2.4.5 for windows port version进行一些性能分析。我写了一个pub / sub应用程序,我有一个窗口服务作为订阅者。和另一个充当发布者的窗体。
我注意到从发布者那里发送了大约50 ++个连续的消息。订阅者停止响应新消息。发布者方面没有例外。
两个版本的Redis都发生了相同的行为。
有没有人经历过这种奇怪的行为?
这是我的Windows窗体(发布商)的代码:
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)));
}
这是我订阅者的代码:
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);
}
}
感谢。
答案 0 :(得分:0)
您是否尝试使用以下命令打开终端:redis-cli psubscribe“*”以查看即使用户挂起您的邮件是否仍然发送?
问题似乎肯定来自onMessage
侦听器内部,删除以下行:
_subscription.UnSubscribeFromChannels(_channelName);
_subscription.SubscribeToChannels(_channelName);
它应该有用。