Prerequisites
- localstack container is running
- You have access to a Fluent account
There is a script `localstack-setup.sh` bundled with the project that can be used to set up localstack. The script requires some parameters to be configured before it can be executed.It is best to do the following:First, run this command to open a session with the localstack containerThen use the commands below to create the secrets, but ensure to update the variables: $ACCOUNT, $RETAILER, $USERNAME, $PASSWORD and $REGION. Regions values are: sydney, dublin, singapore or north_america.- API key/secret for communicating with external network
When communicating with an external network/platform from its client API interface, it always requires some kind of key or token used for access.
A script `localstack-setup.sh` is bundled with the project that can be used to set up localstack and the necessary credentials. The script requires some parameters to be configured before it can be executed.
Script Execution:
First, run this command to open a session with the localstack containerdocker exec -it localstack /bin/bash Then use the commands below to create the secrets. Make sure to update the variables: $ACCOUNT, $EMAIL_SECRET_KEY, $EMAIL_SENDGRID_API_KEY. Please check the localstack-setup.sh script for more details.
For Email:
For Slack:
Create a new Handler for receiving notifications from Fluent Platform:
SDK Default Handler:
A default implementation of [NotificationHandler] i.e. [DefaultNotificationHandler] is provided by the SDK
Note that this handler will read the setting from Fluent OMS with the key: `fc.connect.external-network-notification.<connectorName>.<type>` (E.g: fc.connect.external-network-notification.NOTIFICATION.EVENT-FAILURE-SUMMARY)The setting has the following format :
Note that this handler will read the setting from Fluent OMS with the key: `fc.connect.external-network-notification.<connectorName>.<type>.<notificationType>` (E.g: fc.connect.external-network-notification.NOTIFICATION.EVENT-FAILURE-SUMMARY.email)The setting has the following format :Custom Email Handler:
Any new Notification handler must implement the interface `NotificationHandler` provided by the SDK.Take EmailNotificationHandler as an example:Handling Notification
- The
`processNotification` method is the entry point for the handler. It will be called by the SDK when a new Notification Event is published. - The
`context` parameter contains the message to be processed along with some common used SDK services: `EmailNotificationData` : POJO object that contains the FluentOMS Settings for sending the email : `sendFrom`, `sendTo`, `subject`, `rawContent`....`referencingPayload` : A Mapping for the referencing value for the Email Raw Content. > For example: > > You have a raw content of the mail defined inside `FluentOMS Settings` like: > > `Dear {{customerName}},....` > > The {{customerName}} will be replaced by the value of `customerName` by the actual value specified in the message data.
ProcessingEmail Content:
- The conversion from message template to final email content is very basic in this example and the intent is to simply demonstrate the feature - NotificationTemplateProcessor. Please consider proper templating libraries when using it in a production environment.
Sending Email:
For the current example, we are using SendGrid as the email client.- This class scope
`prepareSendGrid` method is used to initialize the `SendGrid` client. The `SendGridData` is a POJO object that contains the apiKey for the `SendGrid` client. - The SendGridData is retrieved from the Credential service. The Credential service is used to retrieve the secret from the Secrets Manager of the localstack.
Slack Notification Handler:
We are going to follow the same approach as the Email Handler.This sample implementation is used for both email and slack: DefinedTemplateNotificationHandler.The only difference is how we are going to set up mandatory configuration as a Slack client to send notification.For detail steps, please refer to this link Sending Message Using Slack Web hook.
Schedule Job Handler to Monitoring failed events
Trigger a Job:Example of the CURL with the replaced values: