Git Product home page Git Product logo

livewin-chat's Introduction

livewin-chat(live 聊天室服务)

轻量化分布式消息订阅系统,订阅端使用websocket协议。

Features

  • Subscriber需要唯一标识,Publisher支持批量给多个Subscriber发消息。
  • Subscriber可以订阅一个频道(Channel),PublisherChannel发消息,每一个在线Subscriber都能收到消息。
  • Publisher还可以发广播消息(Broadcast),每一个在线Subscriber都能收到消息。

Note

注意这个livewin-chat暂时不支持离线消息

架构设计

架构图

  • Broker

    Broker主要负责和客户端维护链接,接收消息并且推送给客户端。Broker需要集群化以支持更多的连接数。为了好运维和拓展,Broker还需要设计成stateless,可以无限横向拓展,可以放在传统负责均衡后面,在k8s集群中可以在service后面。

  • Publisher_Api_Svc

    Publisher_Api_Svc作为发送信息的接收器,负责接收消息,并将消息推送到各个BrokerPublisher_Api_Svc需要感知到所有的Broker并且和Broker通过grpc通讯,轻量化服务发现可以使用Mdns实现(需要所有服务在同一个内网),这样中可以简化服务组件,大型系统可以使用etcd,consul等服务发现组件,Publisher_Api_Svc可以通过服务发现知道所有的Broker地址。

  • 架构延伸

    超大型消息系统,可以在Publisher_Api_SvcBroker中加入异步消息系统,例如Publisher_Api_Svc接收消息往kafka发,再几个一个服务消费消息,往Broker发消息。kafkatopic可以增加partition来承载更大的消息处理量。

Run demo

start the terminal

$ go run bin/broker/main.go

start another terminal

$ go run bin/publisher_api_svc/main.go

run live server on example folder,it will open http://127.0.0.1:5500/example/index.html in the browser。

start the third terminal

$ curl -d 'broadcast in channel message' 'http://localhost:9653/broadcastinchannel?channel=channel1'
$ curl -d 'broadcast message' 'http://localhost:9653/broadcast'

watch on the browser,it will got the messages。

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.