# Java -------------------------------------------------------------------------------- title: "Introduction" description: "Build a simple microservice using Catalyst Basic I/O Functions and integrate it with Zoho CRM to send automated counter-based email alerts when more than a specific number of leads are created." last_updated: "2026-03-18T07:41:08.683Z" source: "https://docs.catalyst.zoho.com/en/tutorials/microservice/java/introduction/" service: "All Services" related: - Project Directory Structure (/en/cli/v1/project-directory-structure/introduction/) - Java SDK (/en/sdk/java/v1/overview/) - Node.js SDK (/en/sdk/nodejs/v2/overview/) - Zoho CRM (https://www.zoho.com/crm/login.html) -------------------------------------------------------------------------------- # Microservice ### Introduction 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 {{%link href="https://www.zoho.com/crm/login.html"%}}Zoho CRM{{%/link%}}, and enable an automated email alert to be sent when more than a specified number of leads are created in the {{%italics%}}Leads{{%/italics%}}. You can also integrate this function with Zoho Desk if you need to. This microservice is built only using a {{%link href="/en/serverless/help/functions/basic-io"%}}Catalyst basic I/O function{{%/link%}}, and does not contain a {{%link href="/en/cli/v1/working-with-the-client/introduction/"%}}client{{%/link%}} component. It uses the following Catalyst components and the features they provide: 1. {{%link href="/en/cloud-scale/getting-started/introduction/" %}}**Catalyst Cloud Scale**{{%/link%}}: - {{%link href="/en/cloud-scale/help/mail/introduction"%}} **Mail** {{%/link%}}: You must configure the email address from which the email alert will be sent from in Catalyst Mail. - {{%link href="/en/cloud-scale/help/cache/introduction"%}} **Cache** {{%/link%}}: 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. ### Application Logic The microservice's logic can be described as follows: 1. A counter is created for a feature in the function. The feature can be Zoho CRM, Zoho Desk, or any Zoho service you prefer. 2. 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. 3. The current count value is written to the default segment in the cache every time it is updated. 4. 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. 5. After incrementing the counter every time, the function checks if the current counter value has crossed the specified threshold limit. 6. 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. -------------------------------------------------------------------------------- title: "Prerequisites" description: "Build a simple microservice using Catalyst Basic I/O Functions and integrate it with Zoho CRM to send automated counter-based email alerts when more than a specific number of leads are created." last_updated: "2026-03-18T07:41:08.684Z" source: "https://docs.catalyst.zoho.com/en/tutorials/microservice/java/prerequisites/" service: "All Services" related: - CLI Command Reference (/en/cli/v1/cli-command-reference/) - Install Catalyst CLI (/en/getting-started/installing-catalyst-cli/) - Login CLI (/en/cli/v1/login/login-from-cli/) -------------------------------------------------------------------------------- # Prerequisites Before you begin building the application, you must have the following prerequisites installed on your system: {{%list class="bold"%}}1. **Catalyst CLI** \ \ Catalyst CLI contains a host of tools that enable you to initialize, develop, test, and deploy the components of your application from your local machine. We will be working with Catalyst CLI in this tutorial. \ \ You must perform the following actions: 1. **Install Catalyst CLI:** Catalyst CLI is installed through NPM. You must therefore have NPM and Node.js installed on your system before you install the CLI. Refer to the {{%link href="/en/getting-started/installing-catalyst-cli/" %}}**Install Catalyst CLI help page**{{%/link%}} for details on the pre-requisites and the steps to install it. 2. **Log in to Catalyst CLI:** After you install Catalyst CLI, you must authenticate the CLI with your Catalyst account before using it. Refer to the {{%link href="/en/cli/v1/login/login-from-cli/" %}}**CLI Login help page**{{%/link%}} for the steps to login from Catalyst CLI and the various options available for it. <br> <br> {{%/list%}} {{%list class="bold"%}}2. **Any IDE tool for Java function code development** \ \ You can use any IDE to work with the Basic I/O function. Some popular choices include Visual Studio Code, IntelliJ IDEA, Eclipse, and Sublime Text. Download and install an IDE of your choice on your system.{{%/list%}} {{%info image="/images/tutorials/todo-list/vscode.png"%}}If you are a Visual Studio Code IDE user, you can install the {{%bold%}}Catalyst Tools{{%/bold%}} extension, and use your IDE itself in place of the CLI. You can find more details about the Catalyst VS Code extension from this {{%link href="/en/catalyst-extensions/vs-code-extension/introduction/" %}}help section{{%/link%}}.{{%/info%}} {{%list class="bold"%}}3. **Zoho CRM Professional or Enterprise edition** \ \ To integrate the function with Zoho CRM, we will use {{%link href="https://help.zoho.com/portal/en/kb/crm/automate-business-processes/actions/articles/webhooks-workflow" %}}Webhooks{{%/link%}} and associate it with a {{%link href="https://help.zoho.com/portal/en/kb/crm/automate-business-processes/workflow-management" %}}workflow rule{{%/link%}}. Webhooks are not available in the Free edition of Zoho CRM. You can check out the comparisons of various Zoho CRM editions and buy an edition from {{%link href="https://www.zoho.com/crm/comparison.html" %}}this page{{%/link%}}.{{%/list%}} -------------------------------------------------------------------------------- title: "Create a project" description: "Build a simple microservice using Catalyst Basic I/O Functions and integrate it with Zoho CRM to send automated counter-based email alerts when more than a specific number of leads are created." last_updated: "2026-03-18T07:41:08.684Z" source: "https://docs.catalyst.zoho.com/en/tutorials/microservice/java/create-project/" service: "All Services" related: - Project Directory (/en/cli/v1/project-directory-structure/introduction) - Navigating Console (/en/getting-started/navigating-in-the-console) -------------------------------------------------------------------------------- # Create a project Let's {{%link href="/en/getting-started/catalyst-projects"%}}create a Catalyst Project{{%/link%}} from the Catalyst console. 1. Log in to the {{%link href="https://console.catalyst.zoho.com/baas/index"%}}Catalyst Console{{%/link%}} and click **Create New Project**. <br /> 2. Enter the project's name as '**CounterBasedAlert**' in the pop-up window, and click **Create**. <br /> Your project will be created, then opened. -------------------------------------------------------------------------------- title: "Configure the email address" description: "Build a simple microservice using Catalyst Basic I/O Functions and integrate it with Zoho CRM to send automated counter-based email alerts when more than a specific number of leads are created." last_updated: "2026-03-18T07:41:08.685Z" source: "https://docs.catalyst.zoho.com/en/tutorials/microservice/java/configure-mail/" service: "All Services" related: - Catalyst Mail (/en/cloud-scale/help/mail/introduction) -------------------------------------------------------------------------------- # Configure Email Address Let's set up the sender email address which sends the alert email when the counter exceeds its threshold limit. You can learn about Mail, a {{%link href="/en/cloud-scale/getting-started/introduction/" %}}Catalyst Cloud Scale{{%/link%}} component in detail from the {{%link href="/en/cloud-scale/help/mail/introduction"%}}Mail help page{{%/link%}}. To add a new email address in Catalyst: 1. Navigate to the *Cloud Scale* section of ther console, and click **Start Exploring**. <br /> 2. Navigate to **Mail** under the {{%italics%}}Notify{{%/italics%}} section in the console, and click **Add Email** in the {{%italics%}}Email Configuration{{%/italics%}} section. 3. Enter the display name and the email address in the pop-up box. <br /> {{%note%}} {{%bold class="bold-primary"%}}Note:{{%/bold%}} The email address can be a public domain email addresses such as Gmail, Yahoo, and Hotmail, or hosted in your organization's own domain.{{%/note%}} 4. Click **Add Email**. The email address is now added to your Catalyst account. You can find it in the {{%italics%}}Email Configuration{{%/italics%}} page. <br /> Once you add an email address, you must verify it before you can use it. The {{%italics%}}Confirmation Status{{%/italics%}} column displays the verification status for the email address. To confirm the email address, click **Click to confirm**. This will automatically send an email to the email address containing a confirmation code. Enter this confirmation code in the pop-up box and click **Confirm**. <br /> If you don't receive the email with the confirmation code, click **Resend Code**. Once the confirmation code is verified, you can use the address to send emails from Catalyst. -------------------------------------------------------------------------------- title: "Initialize the project" description: "Build a simple microservice using Catalyst Basic I/O Functions and integrate it with Zoho CRM to send automated counter-based email alerts when more than a specific number of leads are created." last_updated: "2026-03-18T07:41:08.685Z" source: "https://docs.catalyst.zoho.com/en/tutorials/microservice/java/initialize-project/" service: "All Services" related: - Initialize Resources (/en/cli/v1/initialize-resources/introduction/) - Project Directory Structure (/en/cli/v1/project-directory-structure/introduction/) -------------------------------------------------------------------------------- # Initialize the Project from the CLI You can now begin working on your Catalyst project from the CLI. The first step is to initialize the project in an empty directory. This will be the home directory of your project and all of the project files will be saved in it. You can learn about initializing a project in detail from the {{%link href="/en/cli/v1/project-directory-structure/introduction"%}}Project Directory Structure help page{{%/link%}}. For this microservice, we will initialize function component. 1. Create a folder for the project on your local machine and navigate to it from the terminal. 2. Initialize a project by executing the following command from that directory: {{%cli%}}catalyst init {{%/cli%}} 3. Select your preferred portal using the arrow-keys, and press **Enter** to select your preferred portal. <br /> 4. The CLI will now ask you to associate a Catalyst project with the directory. Associate it with the project that we created earlier from the console. Select **CounterBasedAlert** from the list and press **Enter**. <br /> 5. Select **Functions** using the space bar. Press the **Enter** key to initialize. <br /> 6. The CLI will initiate the functions set up. Select the {{%link href="/en/serverless/help/functions/basic-io/" %}}**BasicIO**{{%/link%}} type from the list to set up and press **Enter**. You can learn about the function types from the {{%link href="/en/serverless/help/functions/introduction"%}}Functions help page{{%/link%}}. <br /> 7. Select the latest runtime of Java as the stack and press **Enter**. <br /> 8. Enter the name of the Java function and the folder as '**countfunction**'. This is also its reference name. Enter the name of the main class as '**CountAlert** and press **Enter** each time. {{%note%}} {{%bold class="bold-primary"%}}Note:{{%/bold%}} Ensure that you enter the main class name and the function's name exactly as instructed, because the application's code contains the same names.{{%/note%}} The Catalyst Java SDK will now be downloaded to your system. Catalyst initialization is now complete. <br /> The functions directory will be created in your project directory with the configuration files and dependencies, along with the {{%link href="/en/cli/v1/project-directory-structure/introduction"%}}{{%badge%}}catalyst.json{{%/badge%}}{{%/link%}} and a hidden {{%badge%}}.catalystrc{{%/badge%}} file. -------------------------------------------------------------------------------- title: "Configure the Basic I/O function" description: "Build a simple microservice using Catalyst Basic I/O Functions and integrate it with Zoho CRM to send automated counter-based email alerts when more than a specific number of leads are created." last_updated: "2026-03-18T07:41:08.685Z" source: "https://docs.catalyst.zoho.com/en/tutorials/microservice/java/configure-function/" service: "All Services" related: - Functions (/en/serverless/help/functions/introduction) - Functions Directory (/en/cli/v1/project-directory-structure/functions-directory) -------------------------------------------------------------------------------- # Configure the Function Let's begin coding the microservice. The {{%link href="/en/cli/v1/project-directory-structure/functions-directory"%}}functions directory{{%/link%}}, in this case {{%badge%}}functions/countfunction{{%/badge%}}, contains: * The {{%badge%}}CountAlert.java{{%/badge%}} main function file * The {{%badge%}}catalyst-config.json{{%/badge%}} configuration file * The JAR library files * Other dependencies We will be adding code in the {{%badge%}}CountAlert.java{{%/badge%}} file. You can use any IDE of your choice to configure the function. {{%note%}} {{%bold class="bold-primary"%}}Note{{%/bold%}}: Please go through the code given in this section for understanding it better.{{%/note%}} Copy the code given below and paste it in {{%badge%}}CountAlert.java{{%/badge%}} and save the file. {{% panel_with_adjustment header="CountAlert.java" footer="button" class="language-java line-numbers" scroll="set-scroll" %}}import com.catalyst.Context; import com.catalyst.basic.BasicIO; import com.catalyst.basic.ZCFunction; import com.zc.component.cache.ZCCache; import com.zc.component.mail.ZCMail; import com.zc.component.mail.ZCMailContent; import java.util.logging.Logger; import java.util.logging.Level; public class CountAlert implements ZCFunction { private static final Logger LOGGER = Logger.getLogger(CountAlert.class.getName()); private static final String FROM_EMAIL="emma@zylker.com"; // The email address of the sender. Replace this with the email address you configured in Mail. private static final String TO_EMAIL="brandon.cooper@zylker.com"; // Replace this with the email address that you want the alert email to be sent to. @Override public void runner(Context context, BasicIO basicIO) throws Exception { try { // Passes the feature name that was obtained from the input as the parameter. The feature name can be 'CRM' or 'Desk'. String featureName = (String) basicIO.getParameter("feature_name"); // Passes the threshold count that was obtained from the input as the parameter String mailCountThreshold = (String) basicIO.getParameter("mail_count_threshold"); // Gets the current count for the feature from the default segment of Catalyst Cache String value = ZCCache.getInstance() .getCacheValue("COUNTER_" + featureName) .getValue(); // If the value is null, then the count is set to 1. This is done during the first execution for the feature. if (value == null) { ZCCache.getInstance() .putCacheValue("COUNTER_" + featureName, String.valueOf(1), 1l); } else { Integer count = Integer.valueOf(value); // If the value is not null, then the count is incremented by 1. count++; // Writes the count value to the default segment of Catalyst cache ZCCache.getInstance().putCacheValue("COUNTER_"+featureName,count.toString(),1l); // If the current count is greater than the threshold value, then an email alert is sent to the receiver configured above if (count > Integer.valueOf(mailCountThreshold)) { ZCMailContent content = ZCMailContent.getInstance(); content.setFromEmail(FROM_EMAIL); content.setSubject("Alert!"); content.setContent("Count exceeded the threshold limit for the feature:" +featureName); content.setToEmail(TO_EMAIL); ZCMail.getInstance() .sendMail(content); LOGGER.log(Level.INFO, "Email alert sent");//Written to the logs. You can view this log from Logs under the Monitor section in the console } } // Handles the 200 status code basicIO.setStatus(200); basicIO.write("The function executed successfully"); }catch(Exception e) { LOGGER.log(Level.SEVERE,"Exception occurred while processing",e); //Written to the logs. You can view this log from Logs under the Monitor section in the console // Handles the 500 status code, when an exception occurs basicIO.setStatus(500); basicIO.write("Error in the function execution"); } } } {{% /panel_with_adjustment %}} {{%note%}} {{%bold class="bold-primary"%}}Note{{%/bold%}}: Before you proceed to the next step, ensure that you replace the values of {{%badge%}}**FROM_EMAIL**{{%/badge%}} in line {{%bold%}}14{{%/bold%}} and {{%badge%}}**TO_EMAIL**{{%/badge%}} in {{%bold%}}16{{%/bold%}} in the code as directed.{{%/note%}} <br /> ### Working of the Basic I/O function As discussed in the Introduction, the function obtains the inputs for {{%badge%}}feature_name{{%/badge%}} and {{%badge%}}mail_count_threshold{{%/badge%}} variables from the user through the API, when it is invoked. It obtains the current counter value from the cache and then increments it by 1 after every invocation. It then writes the new counter value to the cache. {{%note%}} {{%bold class="bold-primary"%}}Note:{{%/bold%}} Since we are using the default segment in Catalyst Cache, we need not configure it. You can learn more about this from the {{%link href="/en/cloud-scale/help/cache/introduction"%}}Cache help page{{%/link%}}.{{%/note%}} If the current counter value is greater than the threshold limit specified by the user, the email alert is sent to the address defined in the code. This information is also pushed to {{%link href="/en/devops/help/logs/introduction"%}}Catalyst Logs{{%/link%}} with an appropriate message. You can check this from {{%italics%}}Logs{{%/italics%}} under the {{%italics%}}Monitor{{%/italics%}} section in the Catalyst console. The functions directory is now configured. -------------------------------------------------------------------------------- title: "Test the function" description: "Build a simple microservice using Catalyst Basic I/O Functions and integrate it with Zoho CRM to send automated counter-based email alerts when more than a specific number of leads are created." last_updated: "2026-03-18T07:41:08.687Z" source: "https://docs.catalyst.zoho.com/en/tutorials/microservice/java/test-function/" service: "All Services" related: - Serve Resources (/en/cli/v1/serve-resources/introduction) -------------------------------------------------------------------------------- # Test the Function Before you deploy the function to the remote console and integrate it with Zoho CRM, you can test it locally and check if everything works fine. You can test and debug a function by launching a node shell from the Catalyst CLI. You can learn about the functions shell in detail from the {{%link href="/en/cli/v1/working-with-functions/functions-shell/"%}}Working with Functions help page{{%/link%}}. Let's test the function by launching the functions shell in the CLI. Navigate to your project directory in your terminal and execute the following command from the CLI: {{%cli%}}catalyst functions:shell{{%/cli%}} This opens the node shell. You can now pass inputs, execute the function, and perform other node shell operations in it. {{%note%}} {{%bold class="bold-primary"%}}Note:{{%/bold%}} You can launch the function shell with your IDE's debugger attached to it. This will enable you to debug the function line by line in your IDE. You can do this by executing the command: {{%badge%}}{{%link href="/en/cli/v1/working-with-functions/functions-shell/#--debug-port"%}}catalyst functions:shell --debug [port] {{%/link%}}{{%/badge%}}.{{%/note%}} <br /> Let's test the {{%badge%}}countfunction{{%/badge%}} by passing the input values for {{%badge%}}feature_name{{%/badge%}} and {{%badge%}}mail_count_threshold{{%/badge%}}. Execute this command in the function shell: {{%cli%}}countfunction({"feature_name":"CRM","mail_count_threshold":"1"}){{%/cli%}} This assigns the threshold value as '1' for the feature 'CRM'. Therefore, when the function is invoked more than once for the feature, the counter will exceed the threshold limit. <br /> The CLI will invoke the function and pass the input values to the default segment in {{%link href="/en/cloud-scale/help/cache/introduction/" %}}Catalyst Cache{{%/link%}}. The counter doesn't exceed the threshold during the first invocation. Therefore, the CLI will just display the output message that we configured for the status code 200. <br /> You can verify if the counter value is added to the cache, by navigating to **Cache** under {{%italics%}}Storage{{%/italics%}} in the {{%link href="/en/cloud-scale/getting-started/introduction/" %}}**Cloud Scale**{{%/link%}} section of the Catalyst console. <br /> Click **Default** to open the default segment in the Segments page. You will be able to see a key-value pair added to the segment, with the key name '**COUNTER_CRM**' and the value '**1**' indicating that the function was invoked once. <br /> Now let's invoke the function a second time to exceed the threshold limit. Execute the {{%badge%}}countfunction({"feature_name":"CRM","mail_count_threshold":"1"}){{%/badge%}} command again. This will invoke the function again and increment the counter value. Since the threshold limit of 1 has now been exceeded, the email alert will be sent automatically to the defined receiver email address. The CLI will display the message that was pushed to the logs indicating this. <br /> You can verify this by checking the receiver email. <br /> The value of the counter will also be updated in the cache. If this setup is working correctly, we can deploy the application to production. Once you’ve finished testing in the function shell, type {{%badge%}}.exit{{%/badge%}} to exit the shell. -------------------------------------------------------------------------------- title: "Deploy the function" description: "Build a simple microservice using Catalyst Basic I/O Functions and integrate it with Zoho CRM to send automated counter-based email alerts when more than a specific number of leads are created." last_updated: "2026-03-18T07:41:08.688Z" source: "https://docs.catalyst.zoho.com/en/tutorials/microservice/java/deploy-project/" service: "All Services" related: - Deploy Resources (/en/cli/v1/deploy-resources/introduction) -------------------------------------------------------------------------------- # Deploy the Function To {{%link href="/en/cli/v1/deploy-resources/introduction"%}}deploy your Catalyst project from the CLI{{%/link%}}, run the following command in your terminal from your project directory: {{%cli%}}catalyst deploy{{%/cli%}} <br /> The function is deployed and the production URL of the function is displayed. <br /> This function will now be available in your Catalyst console. Navigate to **Functions** under {{%italics%}}FAAS{{%/italics%}} in the {{%link href="/en/serverless/getting-started/introduction/" %}}Serverless{{%/link%}} section of the Catalyst console. <br /> You can click **countfunction** from the {{%italics%}}Functions{{%/italics%}} page to view its statistics for the day. {{%note%}} {{%bold class="bold-primary"%}}Note:{{%/bold%}} You will not be able to edit a Java function from the console. The provision for this will be rolled out soon.{{%/note%}} -------------------------------------------------------------------------------- title: "Integrate the function with Zoho CRM" description: "Build a simple microservice using Catalyst Basic I/O Functions and integrate it with Zoho CRM to send automated counter-based email alerts when more than a specific number of leads are created." last_updated: "2026-03-18T07:41:08.688Z" source: "https://docs.catalyst.zoho.com/en/tutorials/microservice/java/intergrate-crm/" service: "All Services" related: - Functions (/en/serverless/help/functions/introduction) -------------------------------------------------------------------------------- # Integrate the Function with Zoho CRM Let's now integrate this function with Zoho CRM by creating a workflow rule with a webhook associated to it. You can go through the {{%link href="https://www.zoho.com/crm/help/"%}}help resources for Zoho CRM{{%/link%}} to understand it better. To learn about Workflow Management refer to {{%link href="https://help.zoho.com/portal/en/kb/crm/automate-business-processes/workflow-management"%}}this help page{{%/link%}}. To learn about Webhooks, refer to {{%link href="https://help.zoho.com/portal/en/kb/crm/automate-business-processes/actions/articles/webhooks-workflow"%}}this help page{{%/link%}}. To integrate the function with Zoho CRM: 1. Navigate to **Setup** and then **Workflow Rules** under the {{%italics%}}Automation{{%/italics%}} section. <br /> 2. Click **Create Rule** in the {{%italics%}}Workflow Rules{{%/italics%}} page. <br /> 3. Select the **Leads** module and enter the rule name and description in the pop-up box as displayed below. Click **Next**. <br /> 4. Select **Create** and click **Next**. <br /> 5. Select **All Leads** and click **Next**. <br /> 6. Click **Instant Actions** and select **Webhooks**. <br /> 7. Enter the details as displayed below in the pop-up box. You can obtain the Function URL from the Catalyst console or from the CLI as discussed in the previous step. You must append this at the end of the Function URL as shown in the picture: "**?feature_name=CRM&mail_count_threshold=5**". Select the HTTP method as **GET**. Click **Save and Associate**. The workflow rule will now be saved and webhook will be associated with it. We have defined the threshold as "5". Therefore, if more than 5 leads are created in the Leads module, the email alert will be sent automatically. The microservice is now functional and will work without any errors.