Coder Social home page Coder Social logo

gim's Introduction

GIM

golang实现的基于内存的聊天服务

架构

im

功能

  • 支持私聊与群聊的消息发送
  • 支持按会话查询历史消息
  • 支持查询群成员

特性

  • 推送策略:私聊全量推送,群聊按时间间隔推送最新n条数据
  • 消息策略:通过SortedSet数据结构实现消息存储,按发送时间排序

启动服务

go run cmd/main.go
  • 查看帮助
> go run cmd/main.go --help
NAME:
   gim - simple and fast im service

USAGE:
   gim [global options] command [command options] [arguments...]

VERSION:
   1.0.0

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --api-address value, --http value          Set http server bind address (default: ":8081")
   --gateway-address value, --ws value        Set websocket server bind address (default: ":8080")
   --gateway-worker value, --ws-worker value  Set websocket server worker number (default: 8)
   --help, -h                                 show help (default: false)
   --profiling-enabled, --profiling           Set pprof switch (default: false)
   --trace-header value, --trace value        Set trace header (default: "trace")
   --version, -v                              print the version (default: false)

选项设计

--enable-profiling: 是否开启pprof
--gateway-address: websocket网关地址
--api-address: http接口地址
--message-protocol: 消息协议(json,proto)
--enable-message-sequence: 是否开启消息sequence
--message-push-count: 每次推送消息条数
--message-push-duration: 每次推送时间间隔
--message-push-concurrency-limit: 消息推送并发上限
--storage: 存储类型(memory, redis)

应用领域

  • 游戏
    支持高并发,低带宽的功能特性
--enbale-message-sequence=false 
  • 社交 支持低延时,高可达率的功能特性
--enbale-message-sequence=true

连接测试

# install websocket client
npm install -g wscat

# connect
wscat.cmd -c ws://127.0.0.1:8080 # windows
wscat -c ws://127.0.0.1:8080 # linux

# login
{"op":101,"body":"{\"id\":\"1001\"}"}

# send heartbeat
{"op":105}

# send private message
{"op":201,"body":"{\"content\":\"test\",\"type\":2,\"category\":\"text\",\"target_id\":\"1002\"}"}

# join chatroom
{"op":301,"body":"{\"id\":\"9999\"}"}

# send chatroom message
{"op":201,"body":"{\"content\":\"test\",\"type\":1,\"category\":\"text\",\"target_id\":\"9999\"}"}


# list session
{"op":205}

# query history message
{"op":203,"body":"{\"session_id\":\"1:9999\"}"}

gim's People

Contributors

hongker avatar

Stargazers

Roman avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.