This tutorial will help you build a simple microservice in Java using Catalyst Functions. This microservice sends an automated email alert when the counter in the function exceeds the threshold limit defined by the user.
In this tutorial, we will integrate this function with Zoho CRM, and enable an automated email alert to be sent when more than a specified number of leads are created in the Leads module. You can also integrate this function with Zoho Desk if you need to.
This microservice is built only using a Catalyst basic I/O function, and does not contain a client or an app logic component. It uses the following Catalyst features:
- Mail: You must configure the email address from which the email alert will be sent from in Catalyst Mail.
- Cache: The Java function writes to and reads the current counter value from the default segment in Catalyst Cache.
We will use the Catalyst web console and the Catalyst Command Line Interface (CLI) to build this application. In this tutorial, we have provided the code to be included in the function file. You will just have to copy the code and paste it into the appropriate file.
The microservice's logic can be described as follows:
- A counter is created for a feature in the function. The feature can be Zoho CRM, Zoho Desk, or any Zoho service you prefer
- The counter value in the function is increased by 1 every time the function is invoked. For example, every time a lead is created in Zoho CRM, the function is invoked and the counter value is increased by 1. This is done after obtaining the previous counter value from the default segment in the cache.
- The current count value is written to the default segment in the cache every time it is updated.
- A threshold limit for the counter is defined by the user and passed through the API from Zoho CRM or Zoho Desk, along with the feature's name.
- After incrementing the counter every time, the function checks if the current counter value has crossed the specified threshold limit.
- When the number of function invocations crosses the threshold limit, an automated email is sent to the user alerting them of the counter exceeding the limit.