Skip to content

Commit

Permalink
Add Credentials for RabbitMQ (#38)
Browse files Browse the repository at this point in the history
* first pass at adding username + password for MQ

* moving credentials

* Fix up credentials and make rabbitmq optional

---------

Co-authored-by: Five Grant <5@fivegrant.com>
  • Loading branch information
Tom-Szendrey and fivegrant authored Aug 15, 2023
1 parent 6cfe408 commit e9a6057
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ endif
# Turn project on
.PHONY:up
up:docker/docker-compose.yaml
$(DOCKER_COMPOSE) compose --file $(DOCKER_COMPOSE_YAML) up -d
$(DOCKER_COMPOSE) compose --profile standalone --file $(DOCKER_COMPOSE_YAML) up -d

# Rebuild all containers and turn project on
.PHONY:up-rebuild
up-rebuild:$(DOCKER_COMPOSE_YAML)
$(DOCKER_COMPOSE) compose --file $(DOCKER_COMPOSE_YAML) up --build -d
$(DOCKER_COMPOSE) compose --profile standalone --file $(DOCKER_COMPOSE_YAML) up --build -d

# Rebuild the docker image from scratch
.PHONY:up-rebuild
.PHONY:force-rebuild
force-rebuild:$(DOCKER_COMPOSE_YAML)
$(DOCKER_COMPOSE) compose --file $(DOCKER_COMPOSE_YAML) build --no-cache

# Turn project off
.PHONY:down
down:$(DOCKER_COMPOSE_YAML)
$(DOCKER_COMPOSE) compose --file $(DOCKER_COMPOSE_YAML) down
$(DOCKER_COMPOSE) compose --profile standalone --file $(DOCKER_COMPOSE_YAML) down

# Restart project
.PHONY:restart
Expand Down
4 changes: 3 additions & 1 deletion docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ services:
depends_on:
- redis
- api
- rabbitmq
networks:
- data-api
- pyciemss
rabbitmq:
container_name: rabbitmq
profiles: ["standalone"]
hostname: rabbitmq
image: 'rabbitmq:3'
healthcheck:
Expand All @@ -57,10 +57,12 @@ services:
retries: 5
ports:
- "5672:5672"
- "15672:15672"
networks:
- pyciemss
rabbitmq-mock-consumer:
container_name: rabbitmq-mock-consumer
profiles: ["standalone"]
build:
context: ..
dockerfile: docker/Dockerfile.api
Expand Down
2 changes: 2 additions & 0 deletions env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ REDIS_HOST=redis
REDIS_PORT=6379
RABBITMQ_HOST=rabbitmq.pyciemss
RABBITMQ_PORT=5672
RABBITMQ_USERNAME=guest
RABBITMQ_PASSWORD=guest
2 changes: 2 additions & 0 deletions service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Settings(BaseSettings):
REDIS_PORT: int = 6379
RABBITMQ_HOST: str = "rabbitmq.pyciemss"
RABBITMQ_PORT: int = 5672
RABBITMQ_USERNAME: str = "guest"
RABBITMQ_PASSWORD: str = "guest"


settings = Settings()
7 changes: 5 additions & 2 deletions service/utils/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

from settings import settings

creds = pika.PlainCredentials(settings.RABBITMQ_USERNAME, settings.RABBITMQ_PASSWORD)
conn_config = pika.ConnectionParameters(
host=settings.RABBITMQ_HOST, port=settings.RABBITMQ_PORT
host=settings.RABBITMQ_HOST, port=settings.RABBITMQ_PORT, credentials=creds
)


Expand All @@ -33,7 +34,9 @@ def callback(ch, method, properties, body):


def gen_rabbitmq_hook(job_id):
connection = pika.BlockingConnection(conn_config)
connection = pika.BlockingConnection(
conn_config,
)
channel = connection.channel()

def hook(progress):
Expand Down

0 comments on commit e9a6057

Please sign in to comment.