The Notification building block enables sending emails via SendGrid service. It can receive informations - To, From, Subject, and Body via API as well as Kafka topic and sends the email using Sendgrid service, the credentials of which can be configured in the .env file. This service also maintains a log of all the emails sent in the Postgres.
- Operating System: Ubuntu 22
- Node.js: v20
- PostgreSQL: 16
- Citus: 12.1
- Apache Kafka: 3.5.0
Elevate notification services can be setup in local using two methods:
Dockerized service with local dependencies(Intermediate)
Expectation: Run single docker containerized service with existing local (in host) or remote dependencies.
-
Update dependency (Kafka etc) IP addresses in .env with "host.docker.internal".
Eg:
#Kafka Host Server URL KAFKA_URL = host.docker.external:9092
-
Build the docker image.
/ELEVATE/notification$ docker build -t elevate/notification:1.0 .
-
Run the docker container.
-
For Mac & Windows with docker v18.03+:
$ docker run --name notification elevate/notification:1.0
-
For Linux:
$ docker run --name notification --add-host=host.docker.internal:host-gateway elevate/notification:1.0`
Refer this for more information.
-
-
Update dependency (Kafka etc) Ip addresses in .env with respective remote server IPs.
Eg:
#Kafka Host Server URL KAFKA_URL = 11.2.3.45:9092
-
Build the docker image.
/ELEVATE/notification$ docker build -t elevate/notification:1.0 .
-
Run the docker container.
$ docker run --name notification elevate/notification:1.0
Local Service with local dependencies(Hardest)
Expectation: Run single service with existing local dependencies in host (Non-Docker Implementation).
Refer to the NodeSource distributions installation scripts for Node.js installation.
$ curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
$ sudo apt-get install build-essential
Refer to Kafka Ubuntu 22.04 setup guide
-
Install OpenJDK 11:
$ sudo apt install openjdk-11-jdk
-
Download and extract Kafka:
$ sudo wget https://downloads.apache.org/kafka/3.5.0/kafka_2.12-3.5.0.tgz $ sudo tar xzf kafka_2.12-3.5.0.tgz $ sudo mv kafka_2.12-3.5.0 /opt/kafka
-
Configure Zookeeper:
$ sudo nano /etc/systemd/system/zookeeper.service
Paste the following lines into the
zookeeper.service
file:/etc/systemd/system/zookeeper.service [Unit] Description=Apache Zookeeper service Documentation=http://zookeeper.apache.org Requires=network.target remote-fs.target After=network.target remote-fs.target [Service] Type=simple ExecStart=/opt/kafka/bin/zookeeper-server-start.sh /opt/kafka/config/zookeeper.properties ExecStop=/opt/kafka/bin/zookeeper-server-stop.sh Restart=on-abnormal [Install] WantedBy=multi-user.target
Save and exit.
-
Reload systemd:
$ sudo systemctl daemon-reload
-
Configure Kafka:
$ sudo nano /etc/systemd/system/kafka.service
Paste the following lines into the
kafka.service
file:[Unit] Description=Apache Kafka Service Documentation=http://kafka.apache.org/documentation.html Requires=zookeeper.service [Service] Type=simple Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64" ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties ExecStop=/opt/kafka/bin/kafka-server-stop.sh [Install] WantedBy=multi-user.target
Save and exit.
-
Reload systemd:
$ sudo systemctl daemon-reload
-
Start Zookeeper:
$ sudo systemctl start zookeeper
Check status:
$ sudo systemctl status zookeeper
Zookeeper service status should be shown as active (running).
-
Start Kafka:
$ sudo systemctl start kafka
Check status:
$ sudo systemctl status kafka
Kafka status should be shown as active (running).
Refer to How To Set Up a Node.js Application for Production on Ubuntu 22.04.
Run the following command
$ sudo npm install pm2@latest -g
opt/backend$ git clone -b develop-2.5 --single-branch "https://github.com/ELEVATE-Project/notification.git"
backend/notification/src$ sudo npm i
notification/src$ sudo nano .env
Copy-paste the following env variables to the .env
file:
# Notification Service Config
# Port on which service runs
APPLICATION_PORT=3002
# Application environment
APPLICATION_ENV=development
# Route after the base URL
APPLICATION_BASE_URL=/notification/
# Kafka endpoint
KAFKA_HOST="localhost:9092"
# Kafka topic name
KAFKA_TOPIC="dev.notification"
# Kafka consumer group id
KAFKA_GROUP_ID="elevate-notification"
# Sendgrid API key
SENDGRID_API_KEY="SG.asd9f87a9s8d7f."
# Sendgrid sender email address
SENDGRID_FROM_MAIL="[email protected]"
# Api doc URL
API_DOC_URL= "/notification/api-doc"
INTERNAL_ACCESS_TOKEN="internal_access_token"
ERROR_LOG_LEVEL='silly'
DISABLE_LOG=false
DEV_DATABASE_URL=postgres://shikshalokam:slpassword@localhost:9700/elevate_notification
ZEST_ENV= "ZEST_ENV"
created_time= "2023-12-29T17:04:19.017783534Z"
custom_metadata= null
destroyed=false
version=8
Save and exit.
Log into the postgres user
sudo su postgres
Log into psql
psql -p 9700
Create a database user/role:
CREATE USER shikshalokam WITH ENCRYPTED PASSWORD 'slpassword';
Create the elevate_notification database
CREATE DATABASE elevate_notification;
GRANT ALL PRIVILEGES ON DATABASE elevate_notification TO shikshalokam;
\c elevate_notification
GRANT ALL ON SCHEMA public TO shikshalokam;
Exit the postgres user account and install sequelize-cli globally
$ sudo npm i sequelize-cli -g
Navigate to the src folder of notification service and run sequelize-cli migration command:
notification/src$ npx sequelize-cli db:migrate
Now all the tables must be available in the Citus databases
Navigate to the src folder of notification service and run pm2 start command:
notification/src$ pm2 start app.js -i 2 --name elevate-notification
$ pm2 ls
Output should look like this (Sample output, might slightly differ in your installation):
┌────┬─────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├────┼─────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 19 │ elevate-notification │ default │ 1.0.0 │ cluster │ 88026 │ 47h │ 0 │ online │ 0% │ 113.2mb │ jenkins │ disabled │
│ 20 │ elevate-notification │ default │ 1.0.0 │ cluster │ 88036 │ 47h │ 0 │ online │ 0% │ 80.3mb │ jenkins │ disabled │
└────┴─────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
This concludes the service and dependency setup.
npm run test:integration
To know more about integration tests and their implementation refer to the project Wiki.
npm test
This project was built to be used with Mentoring Service and User Service.
You can learn more about the full implementation of various capabilities of ELEVATE here .
Several open source dependencies that have aided Mentoring's development: