How to use the Job Notification Service
1. Introduction
The KRAKEN Team developed the Job Notification Service (JNS) to enable notifications scheduling required by any services to perform recurring or date-specific tasks.
2. High-Level Design
Job Notification Services utilize the following tools and libraries
Azure Service Bus: The service bus is the medium for notification request scheduling and notification events.
Hangfire: Is a simple persistent transparent reliable distributed extensible efficient self-maintainable open-source library enabling background processing in .NET and .NET Core.
CAP: Is an open-source library based on .NET standard, which is a solution to deal with distributed transactions, also has the function of EventBus, it is lightweight, easy to use, and efficient.
3. Notification Scheduling Management
JNS allow creating and deletion of notification jobs.
3.1 Notification Request
Any service can send a request to the JNS service to schedule a notification by distributing a message to the service bus topic named “job-notification-topic” with the following properties:
Content Type: “Application/Json”
Message Label/Subject : “CreateJob”
Content: JSON object using the following schema:
{ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "Id": { "type": "string" }, "Name": { "type": "string" }, "DueDateUTC": { "type": "DateTime" }, "ScheduleCRONUTC": { "type": "string" }, "Content": { "type": "string" }, "CallbackPath": { "type": "string" } }, "required": [ "Id", "Name", "DueDateUTC", "ScheduleCRONUTC", "Content", "CallbackPath" ] }
Notification request example:
{
"Id": "2692c42e-d6c1-48f0-8f88-e00401a1bea9",
"Name": "VesselHistoryCacheRefresh",
"DueDateUTC": "2022-03-03T10:31:37",
"ScheduleCRONUTC": "*/5 * * * *",
"Content": "",
"CallbackPath": "RefreshCache"
}
3.1.1 Notification request message details
The message consists of the following fields:
Id : should be unique id and using a generated GUID is recommended. Value is required
Name: User friendly name used for logging and on the Hangfire dashboard and to identify and delete recurring jobs if needed. Value is required.
DueDateUTC: Where the notification is requested. This value will be ignored if the message has a value in the “ScheduleCRONUTC” field. Accept empty value if “ScheduleCRONUTC” is defined
ScheduleCRONUTC: String containing schedule definition using CRON syntax. Accept empty value is “DueDateUTC” is defined.
Content: Option content to be sent back with the notification message.
CallbackPath: define the Lable/Subject to be applied to the notification message. The service requesting the notification will usually subscribe to the job notification topic with a subscription filter on the same Label/Subject specified in the notification scheduling request.
3.2 Notification Request Deletion
Any service can send a request to the JNS service to delete a scheduled notification by distributing a message to the service bus topic named “job-notification-topic” with the following properties:
Content Type: “Application/Json”
Message Label/Subject : “DeleteScheduleJob”
Content: Job Id, as specified when the Notification Job was created.
To delete a recurring Notification Job the the message should use the following properties:
Content Type: “Application/Json”
Message Label/Subject : “DeleteRecurringJob”
Content: Job Name, as specified when the Notification Job was created.
4. Email Notification by using GC Notify
4.1 Sending an email notification
Event: “email-notification-topic”
Event body:
{
"EmailAddress": "yong.guan@tc.gc.ca",
"TemplateId": "GC Notify template ID",
"Reference": "vr-test",
"Personalisation": {
"user_name": "Yong",
"some_variable": "Email notification test"
},
"ApiKey": "GC Notify api key"
}
4.2 Sending notifications in bulk
Event: “bulkemail-notification-topic”
Event body:
{
"Name": "bulk email name",
"TemplateId": "GC Notify template ID",
"Rows": [
["email address", "user_name", "some_variable"],
["yong.guan@tc.gc.ca", "Yong", "bulk email notification"],
["Anurag.Beechu@tc.gc.ca", "Anurag", "bulk email notification"]
],
"ApiKey": "GC Notify api key"
}
Note: The first column of rows need be “email address“ and emails.
5. CAP Management
5.1 CAP Dashboard
6. Hangfire Management
6.1 Hangfire Dashboard