优秀的编程知识分享平台

网站首页 > 技术文章 正文

聊天系统——gowebsocket(聊天系统架构设计)

nanyue 2024-10-13 04:01:12 技术文章 24 ℃

基于websocket单台机器支持百万连接分布式聊天(IM)系统

本文将介绍如何实现一个基于websocket分布式聊天(IM)系统。

使用golang实现websocket通讯, 单机可以支持百万连接, 使用gin框架、nginx负载、可以水平部署、程序内部相互通讯、使用grpc通讯协议。

https://github.com/link1st/gowebsocket
  • 克隆项目
git clone git@github.com:link1st/gowebsocket.git
# 或
git clone https://github.com/link1st/gowebsocket.git
  • 修改项目配置
cd gowebsocket
cd config
mv app.yaml.example app.yaml
# 修改项目监听端口,redis连接等(默认127.0.0.1:3306)
vim app.yaml
# 返回项目目录,为以后启动做准备
cd ..
  • 配置文件说明
app:
  logFile: log/gin.log # 日志文件位置
  httpPort: 8080 # http端口
  webSocketPort: 8089 # webSocket端口
  rpcPort: 9001 # 分布式部署程序内部通讯端口
  httpUrl: 127.0.0.1:8080
  webSocketUrl:  127.0.0.1:8089


redis:
  addr: "localhost:6379"
  password: ""
  DB: 0
  poolSize: 30
  minIDleConns: 30


  • 启动项目
go run main.go
  • 进入IM聊天地址 http://127.0.0.1:8080/home/index
  • 到这里,就可以体验到基于webSocket的IM系统

Tags:

最近发表
标签列表