Skip to content

feat: add RabbitMQ module and service for message handling #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clinerules-code
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
skip lint error and and format error if have
25 changes: 24 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,31 @@ REDIS_PORT=6379
REDIS_USER=
REDIS_PASS=

# db
POSTGRES_USER=prisma
POSTGRES_PASSWORD=pns123456
POSTGRES_DB=postgres
POSTGRES_HOST=localhost
POSTGRES_PORT=5432

# Prisma database connection
DATABASE_URL=postgresql://prisma:pd8cDXMA@localhost:5432/postgres?schema=public&sslmode=prefer
DATABASE_URL=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB?schema=public&sslmode=prefer

# Kafka Configuration
KAFKA_PORT=9092
KAFKA_CLIENT_ID=nestjs-auth-service
KAFKA_BROKERS=localhost:9092
KAFKA_CONSUMER_GROUP_ID=nestjs-auth-service-group
KAFKA_SSL=false
KAFKA_SASL_MECHANISM=
KAFKA_SASL_USERNAME=
KAFKA_SASL_PASSWORD=

PUBSUB_DRIVER=redis

# Kong Configuration
KONG_ADMIN_URL=http://localhost:8001
KONG_SERVICE_NAME=auth-service
KONG_SERVICE_HOST=localhost
KONG_SERVICE_PORT=4005
KONG_SERVICE_PATH=/api
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin', 'simple-import-sort'],
plugins: ['@typescript-eslint/eslint-plugin'],
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
root: true,
env: {
Expand All @@ -17,6 +17,7 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'simple-import-sort/imports': [
'error',
{
Expand Down
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ module.exports = {
endOfLine: 'lf',
printWidth: 100,
tabWidth: 2,
importOrderParserPlugins: ['decorators-legacy', 'typescript', 'jsx'],
};
10 changes: 10 additions & 0 deletions .vscode/default-snippets-manager.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"cst": {
"prefix": "cst",
"description": "cst",
"scope": "typescript",
"body": [
"constructor() {}"
]
}
}
119 changes: 95 additions & 24 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,116 @@
version: '3.8'
services:
postgres:
image: postgres:13
image: postgres:16
restart: on-failure
ports:
- 5432:5432
- ${POSTGRES_PORT}:${POSTGRES_PORT}
environment:
- POSTGRES_USER=prisma
- POSTGRES_PASSWORD=pd8cDXMA
- POSTGRES_DB=postgres
- DB_PORT=5432
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
- DB_PORT=${POSTGRES_PORT}
- DB_SCHEMA=public
volumes:
- postgres-data:/var/lib/postgresql/data

mongodb:
image: mongo:latest
container_name: mongodb
ports:
- '${MONGODB_PORT:-27017}:27017'
volumes:
- mongodb_data:/data/db
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGODB_USER:-admin}
- MONGO_INITDB_ROOT_PASSWORD=${MONGODB_PASSWORD:-password}
restart: unless-stopped

redis:
image: redis/redis-stack:latest
restart: on-failure
ports:
- 8001:8001
- 6379:6379
- 8011:8001
- ${REDIS_PORT}:6379
volumes:
- redis-data:/data
api:
image: ghcr.io/pnstack/nestjs-auth-service:release
container_name: nestjs-auth-service

zookeeper:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- 22181:2181

kafka:
image: confluentinc/cp-kafka:latest
depends_on:
- postgres
- redis
restart: on-failure
- zookeeper
ports:
- 4005:4005
# volumes:
# - /app/node_modules
# - .:/app
env_file:
- .env
- ${KAFKA_PORT}:9092
environment:
- REDIS_HOST=redis
- DB_HOST=postgres
- DATABASE_URL=postgresql://prisma:pd8cDXMA@postgres:5432/postgres?schema=public&sslmode=prefer
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:29092,OUTSIDE://0.0.0.0:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,OUTSIDE://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,OUTSIDE:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
KAFKA_NUM_PARTITIONS: 1
KAFKA_DEFAULT_REPLICATION_FACTOR: 1
KAFKA_MIN_INSYNC_REPLICAS: 1

kafka-ui:
image: provectuslabs/kafka-ui:latest
ports:
- 8181:8080
depends_on:
- kafka
environment:
KAFKA_CLUSTERS_0_NAME: local
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092
KAFKA_CLUSTERS_0_ZOOKEEPER: zookeeper:2181

# nestjs-auth-service:
# image: ghcr.io/pnstack/nestjs-auth-service:release
# container_name: nestjs-auth-service
# build:
# context: .
# dockerfile: Dockerfile
# depends_on:
# - postgres
# - redis
# restart: on-failure
# ports:
# - 4005:4005
# volumes:
# - /app/node_modules
# - .:/app
# env_file:
# - .env
# environment:
# - REDIS_HOST=redis
# - DB_HOST=postgres
# - DATABASE_URL=postgresql://prisma:pd8cDXMA@postgres:5432/postgres?schema=public&sslmode=prefer

Check failure

Code scanning / SonarCloud

PostgreSQL database passwords should not be disclosed High

Make sure this PostgreSQL database password gets changed and removed from the code. See more on SonarQube Cloud
scylla:
image: scylladb/scylla
container_name: scylla-node1
ports:
- '9042:9042' # CQL
- '7000:7000' # intra-node communication
- '7001:7001' # TLS intra-node
- '7199:7199' # JMX
- '10000:10000' # Alternator (DynamoDB API)
volumes:
- scylla-data:/var/lib/scylla
environment:
- SCYLLA_CLUSTER_NAME=my-scylla-cluster
- SCYLLA_DC=dc1
- SCYLLA_RACK=rack1

volumes:
redis-data:
postgres-data:
mongodb_data:
scylla-data:
23 changes: 23 additions & 0 deletions flow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
id: stock_price
namespace: company.team

tasks:
- id: hello
type: io.kestra.plugin.core.log.Log
message: Hello World! 🚀

- id: send_data
type: io.kestra.plugin.core.http.Request
uri: https://dummyjson.com/products
method: GET
contentType: application/json

- id: get_price
type: io.kestra.plugin.core.http.Request
uri: https://vcbs.com.vn/api/v1/ttpt-companies/VCB?locale=vi
method: GET
contentType: application/json

- id: log
type: io.kestra.plugin.core.log.Log
message: Hello {{outputs.get_price.outputFiles}}
88 changes: 88 additions & 0 deletions kong/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
version: '3'

services:
kong-postgres:
container_name: kong-postgres
image: postgres:16-alpine
environment:
POSTGRES_USER: kong
POSTGRES_DB: kong
POSTGRES_PASSWORD: kong123456
volumes:
- kong_db_data:/var/lib/postgresql/data
restart: always
networks:
- kong-net

kong-migrations:
image: kong:3.1.1-alpine
environment:
KONG_DATABASE: postgres
KONG_PG_HOST: kong-postgres
KONG_PG_PORT: 5432
KONG_PG_USER: kong
KONG_PG_PASSWORD: kong123456
KONG_PG_DATABASE: kong
command: sh -c "kong migrations bootstrap && kong migrations up"
restart: on-failure:5
depends_on:
- kong-postgres
networks:
- kong-net

kong:
image: kong:3.1.1-alpine
environment:
LC_CTYPE: en_US.UTF-8
LC_ALL: en_US.UTF-8
KONG_NGINX_PROXY_PROXY_IGNORE_CLIENT_ABORT: "on"
KONG_DATABASE: postgres
KONG_PG_HOST: kong-postgres
KONG_PG_PORT: 5432
KONG_PG_DATABASE: kong
KONG_PG_USER: kong
KONG_PG_PASSWORD: kong123456
# KONG_DNS_RESOLVER: 10.0.0.224:8600
KONG_DNS_STATE_TTL: 6
KONG_LOG_LEVEL: "error"
KONG_HEADERS: "off"
KONG_PROXY_ACCESS_LOG: /dev/stdout
KONG_ADMIN_ACCESS_LOG: /dev/stdout
KONG_PROXY_ERROR_LOG: /dev/stderr
KONG_ADMIN_ERROR_LOG: /dev/stderr
KONG_ADMIN_LISTEN: 0.0.0.0:8001, 0.0.0.0:8444 ssl
# KONG_PREFIX: /var/run/kong
ports:
- 8180:8000
- 8581:8001
depends_on:
- kong-migrations
# volumes:
# - kong_prefix_vol:/var/run/kong
# - kong_tmp_vol:/tmp
restart: always
networks:
- kong-net

konga:
image: pantsel/konga
restart: always
ports:
- 8182:1338
environment:
- NODE_ENV=develop
- NO_AUTH=true
depends_on:
- kong-postgres
- kong
networks:
- kong-net

networks:
kong-net:
driver: bridge

volumes:
kong_db_data:
# kong_prefix_vol:
# kong_tmp_vol:
Loading