Implementation Design for Notification Service
Implementation Architecture
The above figure illustrates the components of notification service.Notification Service should be implemented with the following technical stacks:
Nodejs-Express (Typescript)
Kafka Scheduler
Samza Processor
Sequence Diagram
Components Description
Notification Service contains the following blocks.
- Route Handler
- Middle-ware
- Service
- Kafka Producer Adaptor
- Templates
Route Handler
Route handler receives the incoming request for a particular route and forwards it to service layer after validation.
Middleware
Middleware is responsible for validating the authorisation and request data and should throw the error response if the request is invalid.
Service
Service part of notification scheduler is responsible for pushing the request data as notification messages into the Kafka queue(to specific topic based on priority) and responding the client with appropriate success message.
Templates
Templates should be managed by Notification Service as local file or as the cloud file.Format of the template file should be json with following format:
[{ "name": "WELCOME_MSG", "templateText": "Hi $firstName ,<p> welcome to Sunbird.Please <a href='$loginLink'>Click here</a> to login to your account.</p>", "fields":["firstName","loginLink"], "mandatoryFields":["firstName","loginLink"] }]
**Note
The templates file storage settings (cloud or local) should be configured in the environment variables.If the storage type is cloud like S3 then respective credentials for accessing them should also configured.
Samza Stream Processor
Samza Message Processor will read messages from Kafka queue and send them with appropriate broadcast adapters (email,sms etc).Also in-case of failures in sending message it will push that back into Kafka`s failed topics after maximum number of retries or message expiry.
API Specs
To create a notification through notification service client should make the request in following format:
POST notification/v1/create { "request": {"recipients":["recipient_1@domain.com","recipient_2@domain.com","recipient_N@domain.com"], "broadcastType":"email", "templateName":"WELCOME_EMAIL", "messageData":[{"data1":"recipient_1"},{"data1":"recipient_2"},{"data1":"recipient_N"}], "priority": "normal" // "immediate" ,"normal" "expiry" : "1543395622" } }
Response
Success
{ "id": "sunbird.notification.create", "ver": "v1", "ts": "2018-11-28 14:25:10", "params": { "resmsgid": null, "msgid": "", "err": "", "status": "success", "errmsg": null }, "responseCode": "OK", "result": { "id": "96ec6fa4-e8d5-4c43-b8c8-0e2dea2cd77f" } }
Error
{ "id": "sunbird.notification.create", "ver": "v1", "ts": "2018-11-28 14:27:37", "params": { "resmsgid": null, "msgid": "", "err": "REQUIRED_PARAMS_MISSING", "status": "REQUIRED_PARAMS_MISSING", "errmsg": "messageData is required" }, "responseCode": "CLIENT_ERROR" }