1

关于使用 Azure Redis 缓存的 Servicestack ServerEvents 的问题。

服务器代码:我在 Global.asax 文件的配置方法下有这些行

Plugins.Add(new ServerEventsFeature { 
OnConnect = (res,httpReq) => res.Publish("cmd.onConnect","Message on connect") ,
OnCreated = (res,httpReq) => res.Publish("cmd.onConnect","Message on create"), 
  ...I have custom message for OnSubscription and OnPublish as well
})

**var redisHost = AppSettings.GetString("RedisHost");
container.Register<IRedisClientsManager>(
    new RedisManagerPool(redisHost));
container.Register<IServerEvents>(c => 
    new RedisServerEvents(c.Resolve<IRedisClientsManager>()));
container.Resolve<IServerEvents>().Start();**

以下是我在 web.config 中用于 redis 连接的值格式

add key="RedisHost" value="passKey@Hostname:6380?ssl=true"

客户代码:

ServerEventConnect connectMsg = null;
var msgs = new List<ServerEventMessage>();
var commands = new List<ServerEventMessage>();
var errors = new List<Exception>();

var client = new ServerEventsClient(baseUri,"home") {
OnConnect = e => connectMsg = e,
OnCommand = commands.Add,
OnMessage = msgs.Add,
OnException = errors.Add,
}.Start();

var connectMsg = client.Connect();

var joinMsg = client.WaitForNextCommand();

connectMsg.Wait();//It gets connnected
joinMsg.Wait(); //When I debug, it is getting lost on this line. I don't get any error message!

当我在 Global.asax (即默认选项 MemoryServerEvents)中删除上面标记的Redis 注册时,效果很好。任何建议,想法都会非常有帮助。谢谢

4

1 回答 1

2

哦上帝..终于我发现了问题所在..它与服务器事件代码或其配置无关!!!但是我在我的应用程序中使用了以下行用于不同的目的,并且对服务器事件产生了影响!

            // Set the default reuse scope for the container to per request
            container.DefaultReuse = ReuseScope.Request;

我猜 onConnect 是第一个请求,而 OnJoin 或其他事件是单独的请求。由于在我的应用程序中设置了重用范围,它无法继续?!如果错了,请分享您的想法。谢谢

于 2015-02-16T11:24:31.777 回答