Azure Event Hubs and Azure Functions, combined with Progress Corticon.js decision services, offer a powerful solution for building scalable and cost-effective event-driven architectures. Azure Event Hubs can seamlessly stream millions of events per second with minimal latency. This data can be streamed from various devices, applications or cloud services. Azure serverless functions can be triggered by these events from the Event Hub. This serverless approach eliminates the need for infrastructure provisioning and management, resulting in significant cost savings.
Furthermore, Corticon.js decision services run as Azure Functions to provide real-time decision-making capabilities.
Corticon.js is a no-code rules engine that empowers business specialists to create, test and maintain complex business logic without having to directly deal with Event Hub and Azure Function technologies.
While business specialists stay focused on the rules, you gain even more productivity.
When they are done with rule creation or maintenance, they simply commit the changes to the source control repository and the CI/CD pipeline, among other steps, produces one or more Corticon.js decision services as JavaScript bundles.
These bundles are ready to execute the business logic as one or more Azure functions. The integration is simple as the bundle can process events directly posted to the Event Hub in JSON format and return JSON data.
Now, let’s look at how simple the integration is.
Calling the Decision Service
Here is a full Azure function example calling a Corticon.js decision service.
// include the decision service generated by Corticon.js
const decisionService = require('./decisionServiceBundle');
const configuration = { logLevel: 0, logFunction: context.log };
module.exports = async function (context, eventHubMessages) {
for (let i = 0; i < eventHubMessages.length; i++) {
const payload = JSON.parse(eventHubMessages[i]);
const result = await decisionService.execute(payload, configuration);
if (result.corticon.status === 'error') {
// add your error processing
// you can access a description of the error
// like this: result.corticon.description
} else {
// successfully executed business logic
context.log(`Result payload: ${JSON.stringify(result)}`);
}
}
};
The two key lines are:
1) Line 2: We include the bundle generated by Corticon.js
2) Line 7: We invoke the decision service with all the payloads from the event hub request
Troubleshooting in Production
Corticon automatically augments the results with a timestamp in UTC ISO 8601 date and time format. Here is what it looks like in the returned JSON:
"timestamp":"2024-04-04T22:55:21.434Z"
We find it very useful to narrow down what is happening when looking at logs. In particular, this timestamp allows querying the Azure Application Insights logs for what specifically happened for this request.
Here are the queries we typically run:
requests | where cloud_RoleName == "replace with yours" and name == "EventHubTrigger2" and timestamp between (todatetime('2024-04-04T22:55:21.000Z') .. todatetime('2024-04-04T22:56:22.000Z'))
From the results, we retrieve, as shown in the image above, the operation_Id, which we use to query the traces table.
Traces where operation_Id == "b8fcb737ca1d58f195b94fd802160a39" limit 100
This will return all the log data for the specific execution we are interested in.
Conclusion
In an Event Hub solution, Corticon.js provides a way to analyze event data and make real-time decisions. This integration empowers businesses to automate processes, personalize experiences and optimize operations based on insights from the data stream.
Corticon allows separating the rules authoring, maintenance and testing from the rest of the solution to help you gain agility and boost productivity. Customers report that they get up to a 90% increase in developing and deploying business logic.
The combined solution (EventHub, Azure Functions and Corticon.js) offers a robust and scalable event-driven architecture that is cost-effective and empowers real-time decision making. This can be a game-changer for businesses looking to transform their operations and gain a competitive edge.
To take the next step, enroll in a free training for Corticon.js. or get familiar with the product by visiting the Corticon.js webpage.
Thierry Ciot
Thierry Ciot is a Software Architect on the Corticon Business Rule Management System. Ciot has gained broad experience in the development of products ranging from development tools to production monitoring systems. He is now focusing on bringing Business Rule Management to Javascript and in particular to the serverless world where Corticon will shine. He holds two patents in the memory management space.