Skip to content

新建ImServer服务端项目 8.6.0

项目介绍

基于FreeIM开发的即时通讯服务端项目,业务和推送分离设计,终端连接永不更新重启 MyImServer ,业务代码全部在 MyApp 项目编写,因此重启 MyApp 项目不会造成连接断开。

每个 MyImServer 管理着对应的终端连接,当接收到 redis 订阅消息后,向对应的终端连接推送数据。

当业务应用 imconfig.json 开启 im 时,同时要启动 im 服务器集群地址中的 im 服务端项目

安装或升级模板

cs
dotnet new install ZhonTai.Template.IMServer

升级模板命令和安装模板命令相同

安装指定版本

cs
dotnet new install ZhonTai.Template.IMServer::9.0.4

查看帮助

cs
dotnet new MyIMServer -h
-p, --port <port>   Port settings
                    类型: int
                    默认: 17010

卸载模板

cs
dotnet new uninstall ZhonTai.Template.IMServer

创建Im服务端项目

cs
dotnet new MyIMServer -n MyCompanyName.MyIMServer

自定义Im服务端端口

cs
dotnet new MyIMServer -n MyCompanyName.MyIMServer -p 17010

appsettings.json

应用程序配置文件

appsettings.json
json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "Urls": "http://*:17010",
  //im服务端配置
  "ImServerConfig": {
    //Redis客户端连接字符串
    "RedisClientConnectionString": "127.0.0.1:6379,password=,poolsize=10,defaultDatabase=6",
    //服务端列表
    "Servers": [ "127.0.0.1:17010" ],
    //服务端
    "Server": "127.0.0.1:17010",
    //输入编码名称
    "InputEncodingName": "GB2312",
    //输出编码名称
    "OutputEncodingName": "GB2312",
    //健康检查
    "HealthChecks": {
      //启用
      "Enable": true,
      //访问路径
      "Path": "/health"
    }
  }
}

注意

redis 默认数据库必须要和业务应用 imconfig.json 中的默认数据库保存一致

launchSettings.json

开发启动配置文件,用于配置启动参数,如环境变量、启动端口等。

launchSettings.json
json
{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:17010",
      "sslPort": 0
    }
  },
  "profiles": {
    "ImServer": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "",
      "applicationUrl": "http://localhost:17010",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}