Skip to content

Commit

Permalink
NOISSUE - Remove multiple brokers (#31)
Browse files Browse the repository at this point in the history
* remove multiple brokers

Signed-off-by: SammyOina <[email protected]>

* Standardize build process on NATS messaging

Removed conditional build flags for different message broker types, making NATS the default and only option. Simplified the Makefile by eliminating the toggleable message broker configuration and related docker-based setup. Updated the NATS URL in docker `.env` and docker-compose service dependency to reflect this change. This adjustment streamlines the build process and reduces configuration complexity.

Resolves issues with inconsistent messaging setups across various environments.

Signed-off-by: SammyOina <[email protected]>

* Refactor message broker configuration

Standardized the environment variable for the message broker URL across services and updated documentation to reflect this change. Renamed the environment variable from COCOS_NATS_URL to COCOS_MESSAGE_BROKER_URL to improve clarity and maintain consistency in service configuration. This alteration facilitates future support for different message broker backends beyond NATS without further variable name changes.

Signed-off-by: SammyOina <[email protected]>

---------

Signed-off-by: SammyOina <[email protected]>
  • Loading branch information
SammyOina authored Dec 24, 2023
1 parent 1fec5fe commit 34c5472
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 108 deletions.
21 changes: 2 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ COCOS_DOCKER_IMAGE_NAME_PREFIX=ghcr.io/ultravioletrs/cocos/
USER_REPO ?= $(shell git remote get-url origin | sed -e 's/.*\/\([^/]*\)\/\([^/]*\).*/\1_\2/' )
empty:=
space:= $(empty) $(empty)
MESSAGE_BROKER_TYPE ?= $(if $(COCOS_MESSAGE_BROKER_TYPE),$(COCOS_MESSAGE_BROKER_TYPE),nats)

define compile_service
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) \
go build -tags $(MESSAGE_BROKER_TYPE) -ldflags "-s -w \
go build -tags nats -ldflags "-s -w \
-X 'github.com/absmach/magistrala.BuildTime=$(TIME)' \
-X 'github.com/absmach/magistrala.Version=$(VERSION)' \
-X 'github.com/absmach/magistrala.Commit=$(COMMIT)'" \
Expand Down Expand Up @@ -74,21 +73,5 @@ protoc:
protoc -I. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative agent/agent.proto
protoc -I. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative manager/manager.proto

define edit_docker_config
sed -i "s/COCOS_MESSAGE_BROKER_TYPE=.*/COCOS_MESSAGE_BROKER_TYPE=$(1)/" docker/.env
sed -i "s,file: .*.yml,file: $(1).yml," docker/brokers/docker-compose.yml
sed -i "s,COCOS_MESSAGE_BROKER_URL=.*,COCOS_MESSAGE_BROKER_URL=$$\{COCOS_$(shell echo ${MESSAGE_BROKER_TYPE} | tr 'a-z' 'A-Z')_URL\}," docker/.env
endef

change_config:
ifeq ($(MESSAGE_BROKER_TYPE),nats)
sed -i "s,COCOS_NATS_URL=.*,COCOS_NATS_URL=nats://broker:$$\{COCOS_NATS_PORT}," docker/.env
$(call edit_docker_config,nats)
else ifeq ($(MESSAGE_BROKER_TYPE),rabbitmq)
$(call edit_docker_config,rabbitmq)
else
$(error Invalid COCOS_MESSAGE_BROKER_TYPE $(MESSAGE_BROKER_TYPE))
endif

run: change_config
run:
docker compose -f docker/docker-compose.yml -p cocos up
25 changes: 13 additions & 12 deletions agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ Agent service provides a barebones HTTP and gRPC API and Service interface imple

The service is configured using the environment variables from the following table. Note that any unset variables will be replaced with their default values.

| Variable | Description | Default |
| ---------------------- | ------------------------------------------------------ | ------------------------------ |
| AGENT_LOG_LEVEL | Log level for agent service (debug, info, warn, error) | info |
| AGENT_HTTP_HOST | Agent service HTTP host | "" |
| AGENT_HTTP_PORT | Agent service HTTP port | 9031 |
| AGENT_HTTP_SERVER_CERT | Path to HTTP server certificate in pem format | "" |
| AGENT_HTTP_SERVER_KEY | Path to HTTP server key in pem format | "" |
| AGENT_GRPC_HOST | Agent service gRPC host | "" |
| AGENT_GRPC_PORT | Agent service gRPC port | 7002 |
| AGENT_GRPC_SERVER_CERT | Path to gRPC server certificate in pem format | "" |
| AGENT_GRPC_SERVER_KEY | Path to gRPC server key in pem format | "" |
| AGENT_JAEGER_URL | Jaeger server URL | http://jaeger:14268/api/traces |
| Variable | Description | Default |
| ------------------------ | ------------------------------------------------------ | ------------------------------ |
| AGENT_LOG_LEVEL | Log level for agent service (debug, info, warn, error) | info |
| AGENT_HTTP_HOST | Agent service HTTP host | "" |
| AGENT_HTTP_PORT | Agent service HTTP port | 9031 |
| AGENT_HTTP_SERVER_CERT | Path to HTTP server certificate in pem format | "" |
| AGENT_HTTP_SERVER_KEY | Path to HTTP server key in pem format | "" |
| AGENT_GRPC_HOST | Agent service gRPC host | "" |
| AGENT_GRPC_PORT | Agent service gRPC port | 7002 |
| AGENT_GRPC_SERVER_CERT | Path to gRPC server certificate in pem format | "" |
| AGENT_GRPC_SERVER_KEY | Path to gRPC server key in pem format | "" |
| AGENT_JAEGER_URL | Jaeger server URL | http://jaeger:14268/api/traces |
| COCOS_MESSAGE_BROKER_URL | Message broker URL | nats://localhost:4222 |

## Deployment

Expand Down
15 changes: 1 addition & 14 deletions docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,7 @@
COCOS_NATS_PORT=4222
COCOS_NATS_HTTP_PORT=8222
COCOS_NATS_JETSTREAM_KEY=u7wFoAPgXpDueXOFldBnXDh4xjnSOyEJ2Cb8Z5SZvGLzIZ3U4exWhhoIBZHzuNvh
COCOS_NATS_URL=nats://broker:${COCOS_NATS_PORT}

## RabbitMQ
COCOS_RABBITMQ_PORT=5672
COCOS_RABBITMQ_HTTP_PORT=15672
COCOS_RABBITMQ_USER=cocos
COCOS_RABBITMQ_PASS=cocos
COCOS_RABBITMQ_COOKIE=cocos
COCOS_RABBITMQ_VHOST=/
COCOS_RABBITMQ_URL=amqp://${COCOS_RABBITMQ_USER}:${COCOS_RABBITMQ_PASS}@broker:${COCOS_RABBITMQ_PORT}${COCOS_RABBITMQ_VHOST}

## Message Broker
COCOS_MESSAGE_BROKER_TYPE=nats
COCOS_MESSAGE_BROKER_URL=${COCOS_NATS_URL}
COCOS_MESSAGE_BROKER_URL=nats://nats:${COCOS_NATS_PORT}

## Jaeger
COCOS_JAEGER_PORT=6831
Expand Down
19 changes: 0 additions & 19 deletions docker/brokers/README.md

This file was deleted.

14 changes: 0 additions & 14 deletions docker/brokers/docker-compose.yml

This file was deleted.

13 changes: 0 additions & 13 deletions docker/brokers/nats.yml

This file was deleted.

11 changes: 0 additions & 11 deletions docker/brokers/rabbitmq.yml

This file was deleted.

22 changes: 17 additions & 5 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ networks:
volumes:
cocos-broker-volume:

include:
- path: brokers/docker-compose.yml
env_file: docker/.env

services:
nats:
image: nats:2.9.21-alpine
container_name: cocos-nats
command: "--config=/etc/nats/nats.conf"
volumes:
- ./nats/:/etc/nats
restart: on-failure
environment:
- COCOS_NATS_PORT=${COCOS_NATS_PORT}
- COCOS_NATS_HTTP_PORT=${COCOS_NATS_HTTP_PORT}
- COCOS_NATS_JETSTREAM_KEY=${COCOS_NATS_JETSTREAM_KEY}
ports:
- ${COCOS_NATS_PORT}:${COCOS_NATS_PORT}
- ${COCOS_NATS_HTTP_PORT}:${COCOS_NATS_HTTP_PORT}
networks:
- cocos-base-net
jaeger:
image: jaegertracing/all-in-one:1.38.0
container_name: cocos-jaeger
Expand All @@ -35,7 +47,7 @@ services:
- /usr/share/edk2/x64/OVMF_CODE.fd:/usr/share/OVMF/OVMF_CODE.fd
- /usr/share/edk2/x64/OVMF_VARS.fd:/usr/share/OVMF/OVMF_VARS.fd
depends_on:
- broker
- nats
- jaeger
networks:
- cocos-base-net
Expand Down
2 changes: 1 addition & 1 deletion manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The service is configured using the environment variables from the following tab
| AGENT_GRPC_CLIENT_TLS | Agent service gRPC client TLS | false |
| COCOS_JAEGER_URL | Jaeger server URL | http://localhost:14268/api/traces |
| MANAGER_INSTANCE_ID | Manager service instance ID | |
| COCOS_MESSAGE_BROKER_URL | message broker url | nats://localhost:4222 |
| COCOS_MESSAGE_BROKER_URL | Mesage broker url | nats://localhost:4222 |

## Deployment

Expand Down

0 comments on commit 34c5472

Please sign in to comment.