From aa7eb1853fcfaf48f25940d0b1dcebde9b78d4e9 Mon Sep 17 00:00:00 2001 From: Ahmed Elwasefi Date: Mon, 6 May 2024 01:12:29 +0300 Subject: [PATCH] Added a lot --- Makefile | 5 +- compose.yaml | 83 +++++++++++-------- services/contracts/.env | 2 + .../src/main/resources/application.properties | 4 +- services/jobs/.env | 2 + services/jobs/cassandra-config/cassandra.yaml | 8 +- .../java/com/workup/jobs/JobsApplication.java | 8 ++ .../src/main/resources/application.properties | 4 +- services/payments/.env | 2 + .../src/main/resources/application.properties | 4 +- 10 files changed, 76 insertions(+), 46 deletions(-) create mode 100644 services/contracts/.env create mode 100644 services/jobs/.env create mode 100644 services/payments/.env diff --git a/Makefile b/Makefile index 46d23f5e..ca4b015b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,10 @@ build: mvn -DskipTests package - docker compose build + docker build ./services/jobs --tag ahmad45123/workup:service_jobs + docker build ./services/payments --tag ahmad45123/workup:service_payments + docker build ./services/users --tag ahmad45123/workup:service_users + docker build ./services/contracts --tag ahmad45123/workup:service_contracts up: docker compose up --force-recreate diff --git a/compose.yaml b/compose.yaml index d41a2778..0c42ce0a 100644 --- a/compose.yaml +++ b/compose.yaml @@ -12,11 +12,8 @@ services: timeout: 30s retries: 3 networks: - - microservices - # ports: - # - "5672:5672" - # - "15672:15672" - + - default + service_redis: image: redis:latest healthcheck: @@ -25,7 +22,7 @@ services: timeout: 30s retries: 3 networks: - - microservices + - default # ports: # - "6379:6379" @@ -36,7 +33,22 @@ services: - jobs_db - service_mq networks: - - microservices + - default + - jobs + env_file: + - ./services/jobs/.env + + jobs_db: + image: cassandra:4.0.7 + volumes: + - ./services/jobs/cassandra-config/cassandra.yaml:/etc/cassandra/cassandra.yaml + healthcheck: + test: [ "CMD", "cqlsh", "-e", "describe keyspaces" ] + interval: 20s + timeout: 10s + retries: 60 + networks: + - jobs # ----- PAYMENTS MICROSERVICE ------- service_payments: @@ -46,26 +58,36 @@ services: - service_mq - service_redis networks: - - microservices + - default + - payments + env_file: + - ./services/payments/.env - # ----- PAYMENTS MICROSERVICE ------- + payments_db: + image: postgres:latest + environment: + POSTGRES_PASSWORD: payments_password + POSTGRES_USER: payments_user + POSTGRES_DB: payments_database + healthcheck: + test: ["CMD", "pg_isready"] + interval: 20s + timeout: 10s + retries: 10 + networks: + - payments + + # ----- CONTRACTS MICROSERVICE ------- service_contracts: image: ahmad45123/workup:service_contracts depends_on: - contracts_db - service_mq networks: - - microservices - - jobs_db: - image: cassandra:4.0.7 - volumes: - - ./services/jobs/cassandra-config/cassandra.yaml:/etc/cassandra/cassandra.yaml - healthcheck: - test: [ "CMD", "cqlsh", "-e", "describe keyspaces" ] - interval: 20s - timeout: 10s - retries: 60 + - default + - contracts + env_file: + - ./services/contracts/.env contracts_db: image: cassandra:4.0.7 @@ -74,20 +96,11 @@ services: interval: 20s timeout: 10s retries: 60 - - payments_db: - image: postgres:latest - environment: - POSTGRES_PASSWORD: payments_password - POSTGRES_USER: payments_user - POSTGRES_DB: payments_database - - healthcheck: - test: ["CMD", "pg_isready"] - interval: 20s - timeout: 10s - retries: 10 + networks: + - contracts networks: - microservices: - driver: overlay + default: + jobs: + payments: + contracts: diff --git a/services/contracts/.env b/services/contracts/.env new file mode 100644 index 00000000..88e9e56f --- /dev/null +++ b/services/contracts/.env @@ -0,0 +1,2 @@ +CONTRACTS_MQ_URL=service_mq +CONTRACTS_DB_URL=contracts_db:9042 diff --git a/services/contracts/src/main/resources/application.properties b/services/contracts/src/main/resources/application.properties index 465575d2..2b246689 100644 --- a/services/contracts/src/main/resources/application.properties +++ b/services/contracts/src/main/resources/application.properties @@ -1,12 +1,12 @@ spring.application.name=contract -spring.rabbitmq.host=localhost +spring.rabbitmq.host=${CONTRACTS_MQ_URL} spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest spring.cassandra.local-datacenter=datacenter1 spring.cassandra.keyspace-name=contracts_data -spring.cassandra.contact-points=localhost:9042 +spring.cassandra.contact-points=${CONTRACTS_DB_URL} spring.cassandra.schema-action=CREATE_IF_NOT_EXISTS diff --git a/services/jobs/.env b/services/jobs/.env new file mode 100644 index 00000000..59921715 --- /dev/null +++ b/services/jobs/.env @@ -0,0 +1,2 @@ +JOBS_DB_URL=jobs_db:9042 +JOBS_MQ_URL=service_mq diff --git a/services/jobs/cassandra-config/cassandra.yaml b/services/jobs/cassandra-config/cassandra.yaml index 426f6d9a..d4f3aba1 100644 --- a/services/jobs/cassandra-config/cassandra.yaml +++ b/services/jobs/cassandra-config/cassandra.yaml @@ -463,7 +463,7 @@ seed_provider: parameters: # seeds is actually a comma-delimited list of addresses. # Ex: ",," - - seeds: "172.18.0.2" + - seeds: "10.0.11.6" # For workloads with more data than can fit in memory, Cassandra's # bottleneck will be reads that need to fetch data from @@ -663,7 +663,7 @@ ssl_storage_port: 7001 # # Setting listen_address to 0.0.0.0 is always wrong. # -listen_address: 172.18.0.2 +listen_address: 10.0.11.6 # Set listen_address OR listen_interface, not both. Interfaces must correspond # to a single address, IP aliasing is not supported. @@ -677,7 +677,7 @@ listen_address: 172.18.0.2 # Address to broadcast to other Cassandra nodes # Leaving this blank will set it to the same value as listen_address -broadcast_address: 172.18.0.2 +broadcast_address: 10.0.11.6 # When using multiple physical network interfaces, set this # to true to listen on broadcast_address in addition to @@ -763,7 +763,7 @@ rpc_address: 0.0.0.0 # be set to 0.0.0.0. If left blank, this will be set to the value of # rpc_address. If rpc_address is set to 0.0.0.0, broadcast_rpc_address must # be set. -broadcast_rpc_address: 172.18.0.2 +broadcast_rpc_address: 10.0.11.6 # enable or disable keepalive on rpc/native connections rpc_keepalive: true diff --git a/services/jobs/src/main/java/com/workup/jobs/JobsApplication.java b/services/jobs/src/main/java/com/workup/jobs/JobsApplication.java index 2c413c1f..df7dd3bb 100644 --- a/services/jobs/src/main/java/com/workup/jobs/JobsApplication.java +++ b/services/jobs/src/main/java/com/workup/jobs/JobsApplication.java @@ -4,6 +4,7 @@ import org.springframework.amqp.core.Queue; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.amqp.support.converter.MessageConverter; +import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @@ -24,4 +25,11 @@ public Queue myQueue() { public MessageConverter messageConverter() { return new Jackson2JsonMessageConverter(); } + + @Bean + public ApplicationRunner runner() { + return args -> { + System.out.println("WE ARE NEW IN JOBS"); + }; + } } diff --git a/services/jobs/src/main/resources/application.properties b/services/jobs/src/main/resources/application.properties index e22173ae..6ef2e3d9 100644 --- a/services/jobs/src/main/resources/application.properties +++ b/services/jobs/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.rabbitmq.host=service_mq +spring.rabbitmq.host=${JOBS_MQ_URL} spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest @@ -6,5 +6,5 @@ spring.rabbitmq.password=guest spring.cassandra.local-datacenter=datacenter1 spring.cassandra.keyspace-name=jobs_data -spring.cassandra.contact-points=jobs_db:9042 +spring.cassandra.contact-points=${JOBS_DB_URL} spring.cassandra.schema-action=CREATE_IF_NOT_EXISTS \ No newline at end of file diff --git a/services/payments/.env b/services/payments/.env new file mode 100644 index 00000000..0e4f643c --- /dev/null +++ b/services/payments/.env @@ -0,0 +1,2 @@ +PAYMENTS_DB_URL=jdbc:postgresql://payments_db:5432/payments_database +PAYMENTS_MQ_URL=service_mq diff --git a/services/payments/src/main/resources/application.properties b/services/payments/src/main/resources/application.properties index 25f9ac46..b125cb1f 100644 --- a/services/payments/src/main/resources/application.properties +++ b/services/payments/src/main/resources/application.properties @@ -1,5 +1,5 @@ spring.application.name=payments -spring.datasource.url=jdbc:postgresql://localhost:5432/payments_database +spring.datasource.url=${PAYMENTS_DB_URL} spring.datasource.username=payments_user spring.datasource.password=payments_password spring.jpa.hibernate.ddl-auto=create-drop @@ -8,7 +8,7 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.jpa.properties.hibernate.format_sql=true server.error.include-message=always -spring.rabbitmq.host=service_mq +spring.rabbitmq.host=${PAYMENTS_MQ_URL} spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest