2881099 / FreeIM

.NETCore websocket 实现简易、高性能、集群即时通讯组件,支持点对点通讯、群聊通讯、上线下线事件消息等众多实用性功能.
MIT License
1.42k stars 418 forks source link

收不到消息 #13

Open feiyit opened 4 years ago

feiyit commented 4 years ago

启动了imServer

启动了Web项目 查看redis也创建了房间,并且2个人员也有了 就是发送消息,双方都看不到? 这是什么问题呢?

2881099 commented 4 years ago

配置发一下看看

2881099 commented 4 years ago

https://github.com/2881099/im/issues/9

这里有个配置好的例子

feiyit commented 4 years ago

imServer的appsetting.json里面配置 "ImServerOption": { "CSRedisClient": "127.0.0.1:6379,defaultDatabase=1,idleTimeout=3000,poolsize=5", "Servers": "127.0.0.1:6001", "Server": "127.0.0.1:6001" }

web startup里面配置 ImHelper.Initialization(new ImClientOptions { Redis = new CSRedis.CSRedisClient("localhost,defaultDatabase=1,idleTimeout=3000,poolsize=5"), Servers = new[] { "127.0.0.1:6001" } });

2881099 commented 4 years ago

imServer 启动方式是:

dotnet run --Urls=http://127.0.0.1:6001

2881099 commented 4 years ago

imServer 的启动方式,要和 "Server" 保持一样

feiyit commented 4 years ago

是的 bogon:imServer apple$ dotnet run --urls=http://127.0.0.1:6001 ���ڶ��ġ�localhost:6379/1��(channels:wsim_wsServerlocalhost:6001)/(chans:wsim_wsServerlocalhost:6001)

不知道为什么有乱码,但是不耽误使用

2881099 commented 4 years ago

channels:wsim_wsServerlocalhost:6001 这个看着不对

怎么是 localhost:6001,这个和 "Server" 是一样才对

你发的配置是 "Server": "127.0.0.1:6001"

2881099 commented 4 years ago

"CSRedisClient": "127.0.0.1:6379,defaultDatabase=1,idleTimeout=3000,poolsize=5", "Servers": "127.0.0.1:6001", "Server": "127.0.0.1:6001"

这三个值特别重要,各端保持一致。

Servers 决定发消息的路由,不一样会导致消息发不到目标上。

然后就是 imServer 的启动方式,要与它的 "Server" 一样,不然 ImHelper.PrevConnectServer 返回的连接,前端连不了。

feiyit commented 4 years ago

服务端肯定是起来了 web项目的socket连接也建立了,我的redis里面已经有房间了,并且有加入的人了 就是双方发送消息都看不到

好奇怪

2881099 commented 4 years ago

servers, server 配置不一样,就会收不到消息。

2881099 commented 4 years ago

你用 redis-cli 连接 redis 执行这个看看:

subscrible channels:wsim_wsServerlocalhost:6001

2881099 commented 4 years ago

然后再发消息

feiyit commented 4 years ago

正在订阅【localhost:6379/1】(channels:wsim_wsServerlocalhost:6001)/(chans:wsim_wsServerlocalhost:6001)

启动imServer 就显示这个,没有返回其他结果吗?比如订阅成功,或者失败?

feiyit commented 4 years ago

我配置的是127.0.0.1 ,怎么变成localhost了呢

feiyit commented 4 years ago

修改了imServer的launchSettings.json,把里面的localhost都换成127.0.0.1了, 运行dotnet run --urls=http://127.0.0.1:6001

提示 正在订阅【127.0.0.1:6379/1】(channels:wsim_wsServer127.0.0.1:6001)/(chans:wsim_wsServer127.0.0.1:6001)

2881099 commented 4 years ago
class ImServer : ImClient
{
    protected string _server { get; set; }

    public ImServer(ImServerOptions options) : base(options)
    {
        _server = options.Server;
        _redis.Subscribe(($"{_redisPrefix}Server{_server}", RedisSubScribleMessage));
    }
}

代码是这样写的,应该是读错了配置文件。

feiyit commented 4 years ago

就是改了,imServer的launchSettings.json 把localhost改成127.0.0.1搞定了

问下,这个imServer必须单独跑是吗?

如果在生产环境,需要搞个服务跑起来么?

2881099 commented 4 years ago

最好单独,单独以后一直运行着。不需要改它。

除非要改 Servers 扩展更多节点。

如果和 webapi 放一起,webapi 更新重启,前端的连接就断了,又得重连

feiyit commented 4 years ago

还有个问题业务上的问题咨询下, 目前我看redis里面没有存消息,那消息要打算存到数据库吗? 为什么不打算存到redis里面呢?

2881099 commented 4 years ago

redis 不适合存有格式数据。用数据库存比较好。

消息发送经过 webapi 的时候,存到数据库或其他介质。

用户上线的时候,也是请求 webapi 查看未读消息。

imserver 职责:管理连接,分区规则。

feiyit commented 4 years ago

ok,感谢