Skip to content
Merged
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
9 changes: 4 additions & 5 deletions services/push_service/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules/
dist/
.env
npm-debug.log*
yarn-error.log*
node_modules
dist
firebase-key.json
.env
4 changes: 0 additions & 4 deletions services/push_service/.prettierrc

This file was deleted.

35 changes: 35 additions & 0 deletions services/push_service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Stage 1: Build
FROM node:18-alpine AS builder

WORKDIR /app

# Copy package.json and lock file
COPY package*.json ./

# Install all dependencies including dev
RUN npm install

# Copy everything
COPY . .

# Compile TypeScript (will create dist/)
RUN npm run build

# Stage 2: Production
FROM node:18-alpine

WORKDIR /app

# Copy only package.json for prod dependencies
COPY package*.json ./

RUN npm ci --only=production

# Copy built files from builder
COPY --from=builder /app/dist ./dist

# Expose NestJS port
EXPOSE 3002

# Start the app
CMD ["node", "dist/main.js"]
71 changes: 67 additions & 4 deletions services/push_service/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,90 @@
# [Service Name]
# [Push Service (NestJS)]

## Overview

Brief explanation of what this service does.
The Push Service is one of the microservices in the Distributed Notification System.
Its responsibility is to:

Receive push notification jobs from RabbitMQ (push.queue)

Fetch user device tokens if missing

Send push notifications using Firebase Cloud Messaging (FCM)

Handle retries with exponential backoff

Publish delivery status updates to the notification.status.queue

Ensure idempotency using request_id

This service works asynchronously and is triggered by messages published from the API Gateway through RabbitMQ.

## Tech Stack

- Framework: NestJS
- Database: PostgreSQL
- Notifications: Firebase Cloud Messaging (FCM)
- Idempotency / Cache: Redis (or in-memory fallback)
- Language: TypeScript
- Queue: RabbitMQ
- Containerization: Docker & Docker Compose

## Setup

Steps to run this service locally.

## Environment Variables
1. Clone the repo
git clone https://github.com/ObiFaith/distributed-notification-system.git

cd distributed-notification-system/push-service

2. Create your .env file

## Environment Variables

List of required `.env` variables.
PORT=3002
RABBITMQ_URL1=amqp://guest:guest@localhost:5672
PUSH_QUEUE=push.queue
RETRY_QUEUE=push.retry.queue
FAILED_QUEUE=push.failed.queue
EXCHANGE=notifications.direct
FCM_SERVICE_ACCOUNT_PATH=./firebase-key.json
REDIS_URL1=redis://127.0.0.1:6379
API_GATEWAY_URL=http://gateway:3000
MAX_RETRY=3
REDIS_HOST=127.0.0.1
REDIS_PORT=6379

3. Add Firebase service account
Place your Firebase Admin SDK JSON file here:
push-service/firebase-key.json

4. Install dependencies
npm install

5. Start services (RabbitMQ, Redis, Push Service) using docker
docker-compose up -d

6. Start the NestJS push service
npm run start:dev

## API Endpoints

Outline of main endpoints or routes.
1. Test push (bypass RabbitMQ)
POST /api/v1/push/test

2. Status callback endpoint
POST /api/v1/push/status

3. Health Check
GET /api/v1/health

## Notes

Any relevant integration or dependency info.


1. Create `.env` based on `.env.example`
2. Place firebase service account at `firebase-key.json`
3. Start services:
34 changes: 34 additions & 0 deletions services/push_service/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:
push-services:
build: .
volumes:
- ./firebase-key.json:/app/firebase-key.json
ports:
- "3002:3002"
environment:
REDIS_URL: redis://redis:6379
RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672
PUSH_QUEUE: push.queue
RETRY_QUEUE: push.retry.queue
FAILED_QUEUE: push.failed.queue
depends_on:
redis:
condition: service_started
rabbitmq:
condition: service_healthy

redis:
image: redis:7-alpine
ports:
- "6379:6379"

rabbitmq:
image: rabbitmq:3-management-alpine
ports:
- "5672:5672"
- "15672:15672" # RabbitMQ management UI
healthcheck:
test: ["CMD", "rabbitmq-diagnostics", "check_running"]
interval: 5s
timeout: 5s
retries: 10
35 changes: 0 additions & 35 deletions services/push_service/eslint.config.mjs

This file was deleted.

10 changes: 10 additions & 0 deletions services/push_service/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: 'src',
testRegex: '.spec.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest'
}
};
8 changes: 0 additions & 8 deletions services/push_service/nest-cli.json

This file was deleted.

Loading