1
0
mirror of https://github.com/ebosas/microservices.git synced 2024-11-24 08:02:24 +02:00
A microservices example in Go
Go to file
2021-06-12 15:31:39 +03:00
cmd Parameters 2021-06-11 14:22:51 +03:00
init Reorganize code, directories 2021-06-08 21:26:14 +03:00
internal Comments 2021-06-08 21:41:51 +03:00
web Update paths 2021-06-11 15:44:47 +03:00
.dockerignore Reorganize code, directories 2021-06-08 21:26:14 +03:00
.env Update readme, .env 2021-06-02 14:43:57 +03:00
.gitignore Reorganize code, directories 2021-06-08 21:26:14 +03:00
backend.Dockerfile Reorganize code, directories 2021-06-08 21:26:14 +03:00
database.Dockerfile Reorganize code, directories 2021-06-08 21:26:14 +03:00
demo.gif Add demo.gif 2021-06-12 15:31:39 +03:00
docker-compose-dev.yml Reorganize code, directories 2021-06-08 21:26:14 +03:00
docker-compose.yml Reorganize code, directories 2021-06-08 21:26:14 +03:00
go.mod Reorganize code, directories 2021-06-08 21:26:14 +03:00
go.sum Reorganize code, directories 2021-06-08 21:26:14 +03:00
LICENSE Initial commit 2021-06-01 09:03:48 +03:00
README.md Add demo.gif 2021-06-12 15:31:39 +03:00
server.Dockerfile Reorganize code, directories 2021-06-08 21:26:14 +03:00

Microservices

A basic example of microservice architecture which demonstrates communication between a few loosely coupled services.

  • Written in Go
  • Uses RabbitMQ to communicate between services
  • Uses WebSocket to talk to the front end
  • Stores data in PostgreSQL
  • Uses React for front end development
  • Builds and runs with Docker

Usage

To run the example, clone the Github repository and start the services using Docker Compose. Once Docker finishes downloading and building images, the front end is accessible by visiting localhost:8080.

git clone https://github.com/ebosas/microservices
cd microservices
docker-compose up

Back end

To access the back end service, attach to its docker container from a separate terminal window. Messages from the front end will show up here. Also, standart input will be sent to the front end for two way communication.

docker attach microservices_backend

Database

To inspect the database, launch a new container that will connect to our Postgres database. Then enter the password demopsw (see the .env file).

docker run -it --rm \
    --network microservices_network \
    postgres:13-alpine \
    psql -h postgres -U postgres -d microservices

Select everything from the messages table:

select * from messages;

RabbitMQ

Access the RabbitMQ management interface by visiting localhost:15672 with guest as both username and password.

Development environment

For development, run the RabbitMQ and Postgres containers with Docker Compose.

docker-compose -f docker-compose-dev.yml up

Generate static web assets for the server service by going to web/react and web/bootstrap and running:

npm run build-server

React

For React development, run npm run serve in web/react and change the script tag in the server's template to the following:

<script src="http://127.0.0.1:8000/index.js"></script>