Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
zarnoevic committed Mar 6, 2024
1 parent dd66b73 commit 6a736b4
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 32 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
example.env
a
diagram.puml
img.png
LICENSE.md
README.md
.github
.idea
.gitignore
docker/
server_exec
client_exec
*.yaml
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ a
*.json
*.js
node_modules/
server_exec
client_exec
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ go run src/cmd/client/main.go
Run the following command to start the Client in a scalable way with docker compose:

```shell
sudo docker-compose -f docker/client.docker-compose.yaml --scale client=2 --env-file .env up -d
docker-compose -f docker/client.docker-compose.yaml --scale client=2 --env-file .env up -d
```

Change the `--scale client=2` parameter to any number of clients you'd want to run in parallel.
Expand All @@ -67,19 +67,28 @@ Change the `--scale client=2` parameter to any number of clients you'd want to r

Run the following command to start the Server on your machine:

#### Without Docker

```shell
go run src/cmd/server/main.go
```

#### With Docker

```shell
docker build -t server -f server.Dockerfile .
docker run --network="host" --env-file .env server
```

#### Scaling the Server

Run the following command to start the Server in a scalable way with docker compose:

```shell
sudo docker-compose -f docker/consumerService.docker-compose.yaml --scale consumerService=2 --env-file .env up -d
docker-compose -f server.docker-compose.yaml --env-file .env up -d --scale server=3
```

Change the `--scale server=2` parameter to any number of clients you'd want to run in parallel.
Change the `--scale server=3` parameter to any number of clients you'd want to run in parallel.

## File structure

Expand All @@ -89,12 +98,11 @@ Change the `--scale server=2` parameter to any number of clients you'd want to r
├── .env
├── go.mod
├── go.sum
├── docker
│   ├── client.Dockerfile
│   ├── client.docker-compose.yaml
│   ├── rabbitmq.docker-compose.yaml
│   ├── server.Dockerfile
│   └── server.docker-compose.yaml
├── client.Dockerfile
├── client.docker-compose.yaml
├── rabbitmq.docker-compose.yaml
├── server.Dockerfile
├── server.docker-compose.yaml
├── resources
│   ├── commands100.csv
│   ├── commands100k.csv
Expand Down
2 changes: 1 addition & 1 deletion docker/client.Dockerfile → client.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM --platform=linux/amd64 golang:1.22 as builder

WORKDIR /app

ADD . /app
ADD docker /app

RUN go mod tidy && go build -o client_exec ./src/cmd/client/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.8'
services:
client:
build:
context: .
context: docker
dockerfile: client.Dockerfile
environment:
RABBITMQ_USER: ${RABBITMQ_USER}
Expand Down
17 changes: 0 additions & 17 deletions docker/server.Dockerfile

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/zarnoevic/go-rabbitmq
go 1.22.0

require (
github.com/joho/godotenv v1.5.1 // indirect
github.com/rabbitmq/amqp091-go v1.9.0 // indirect
github.com/joho/godotenv v1.5.1
github.com/rabbitmq/amqp091-go v1.9.0
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions server.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM --platform=linux/amd64 golang:1.22 as builder

WORKDIR /app

COPY . .

RUN go mod download
RUN go mod tidy
RUN go build -o server_exec ./src/cmd/server/

CMD ["./server_exec"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.8'

services:
client:
server:
build:
context: .
dockerfile: server.Dockerfile
Expand All @@ -11,6 +11,6 @@ services:
RABBITMQ_AMQP_PORT: ${RABBITMQ_AMQP_PORT}
RABBITMQ_AMQP_HOST: ${RABBITMQ_AMQP_HOST}
COMMANDS_PATH: ${COMMANDS_PATH}
network_mode: host
volumes:
- ./resources:/resources

0 comments on commit 6a736b4

Please sign in to comment.