golang-nsq-chat

module
v0.0.0-...-b15ad40 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2018 License: MIT

README

A toy chat app

This project takes ideas from NSQ-Centric Architecture (GoCon Autumn 2014) slide.

Overview

The app contains these parts, but you can add as many as you want:

  • Chat server: Responsible for receiving & sending messages between clients.

  • Archive daemon: Listen for Archive channel & save messages to Mongodb.

  • Bot daemon: Listen for Bot channel, do some analysis, then reply.

 _____________
|   "Chat"    |                  Pub to "Chat" topic
|    Topic    |<-------------------------------------------------------.
|_____________|                                                        |
       |                                                               |
       |            _________________              .----> Client 1 --->|
       |           |     Server1     | Go channels |                   |
       |---------->|   NSQ channel   |------------>|----> Client 2 --->|
       |           |_________________|             |                   |
       |                                           '----> Client 3 --->|
       |            _________________                                  |
       |           |     Server2     | Go channels                     |
       |---------->|   NSQ channel   |------------> ...                |
       |           |_________________|                                 |
       |                                                               |
       |                                                               |
       ...                                                             |
       |            _________________                                  |
       |           |     Archive     |             .---------.         |
       |---------->|   NSQ channel   |------------>| Mongodb |         |
       |           |_________________|             |_________|         |
       |            _________________                                  |
       |           |       Bot       |             .---------------.   |
       |---------->|   NSQ channel   |------------>| NLP, commands |-->|
                   |_________________|             |_______________|

Get started

  1. Start Mongodb
mongod
  1. Start nsq
docker-compose up -d

export NSQLOOKUPD_HTTP_ADDRESS=0.0.0.0:4161
export NSQD_HTTP_ADDRESS=0.0.0.0:4151
  1. Get & Build
go get github.com/manhtai/golang-nsq-chat/cmd/chat
go get github.com/manhtai/golang-nsq-chat/cmd/archive
go get github.com/manhtai/golang-nsq-chat/cmd/bot
  1. Run
  • Chat server
chat
  • Archive daemon
archive
  • Bot daemon
bot

Generate cert.pem & key.pem

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key.pem -out cert.pem

Live reload for Chat server

go get https://github.com/Unknwon/bra
Bra run

Directories

Path Synopsis
cmd
bot
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL