Go Microservices Realtime Finance Chat Application with RabbitMQ, Websockets, JWT, Mux, Gorm(MySQL), And React
The goal of this exercise is to create a browser-based chat application using Go. This application allows several users to talk in one or more chatrooms and also to get stock quotes from an API using a specific command.
The following tools are required to run the project
- Go (Golang)
- RabbitMQ
- MySQL
- Docker(optional)
I use the poly repo ideology, hence, the project works in collaboration with two other repositories:
-
go-stockbot : A decoupled service that calls an API using a "stock_code" as a parameter (https://stooq.com/q/l/?s=aapl.us&f=sd2t2ohlcv&h&e=csv, here aapl.us is the stock_code) and recieves a csv file. The bot parses the received CSV file and then sends a message to the chatroom service using a message broker (RabbitMQ).
Repo Link : https://github.com/omept/go-stockbot-rabbitmq.git -
React client app : The frontend application that allows registered users to log in and talk with other users in a chatroom. It also allows users to post messages as commands into a chatroom with the following format
/stock=stock_code
Repo Link : https://github.com/omept/go-chat-react.git
This service reads published stock bot requests to env.STKBT_RECEIVER_QUEUE queue on RabbitMQ and reads the processed stock response on env.STKBT_PUBLISHER_QUEUE queue on RabbitMQ.
RabbitMQ is the message broker between the bot service and the chat service. To run it with docker, run the folling command in your terminal:
docker run -d --hostname rabbitmq-svc --name rbbtmq -p 15672:15672 -p 5672:5672 rabbitmq:3.11.3-management
copy the .env.example
to .env
and update the entries.
visit this repo: https://github.com/omept/go-stockbot-rabbitmq.git
on steps for stating the app
visit this repo https://github.com/omept/go-chat-react.git
on steps for stating the react frontend app
The table below describes the endpoints available on the app:
#### Routes ⚡
| Routes | HTTP Methods | Params | Description |
| :------------------------- | :----------- | :----------------------------- | :----------------------------------------------- |
| /v1/api/auth/signup | POST | `email` `password` `user_name` | Creates a new user and returns jwt session token |
| /v1/api/auth/login | POST | `email` `password` | Logs in a user and returns the jwt session token |
| /v1/api/chat/create | POST | `name` | Creates a new chat room with the name provided |
| /v1/api/chat/rooms | POST | none | returns a list of chat rooms |
| /v1/api/chat/room-messages | POST | `roomId` | Returns the latest 50 messages in a chat room |
| /v1/ws | GET | none | websocket connection url |
Run the command below to execute tests