Mule 4 — Log Response Time of Message Processors
Take a look at how to log and notify the message processors' response time using mule server notifications.
Join the DZone community and get the full member experience.
Join For FreeEvery API to be developed on any technology will have both Functional and Non Functional Requirements to it.
- Functional Requirements are defined by the client who will use the API.
- Non Functional Requirements are mandatory for any API to make the API available, be consistent, scalable, and perform efficiently.
- Performance is one such metric that defines one of the non-functional requirements.
API Performance
Performance is a key factor to consider if an API is implemented and delivered efficiently and optimally. In any project life cycle, right before the production deployment or Go-Live Non Functional Requirements testing is a mandatory phase. Where performance testing is also carried out.
During the design of any API, we define SLAs with client systems on the response time of an API which when breached is considered as an NFR defect.
And so response time is the base metric that defines the performance of the API.
Whenever we talk about an API, we know that it comprises message processors, API invocations, etc.
API invocations can be of different types like
- Invoking External or Third-Party APIs
- Invoking Process API from Experience API, System API from Process API
The developer will not have any control over the response time of external/third-party APIs since they are being developed by external vendors and they abide by their own SLAs
But when it comes to processing APIs and system APIs, the response times have to be handled independently since they are internal and controlled by the internal developer.
So message processor optimizations are only the way to optimize the performance or response time of overall API.
This article explains the usage of Mule Server Notifications for logging and notifying response times of message processors present in Mule Flows using "Message Processor Notification"
This feature helps a developer during NFR testing if there are any SLA breaches concerning performance metrics.
Use Case
As a developer, I want to optimize the response times of each message processor in a mule flow so that the overall response time of the API is largely optimized.
Implementation Steps
Create a Mule Project
Create a Class — MuleComponentProcessListener in src/main/java folder.
This class implements MessageProcessorNotificationListener Interface where we will be using the onNotification() method to log and notify.
Create beans.xml file in src/main/resources folder
Create a bean as below in beans.xml specifying the class created in step 2 for the type of notification we want to receive.
x
<bean name="messageProcessorNotifications"
class="message_processor_notifications.MuleComponentProcessListener" />
Add beans.xml reference to Spring Configuration as below
x
<spring:config name="springConfig"
doc:name="Spring Config" files="beans.xml" />
- Mule Configuration
We have to specify notifications we want to receive using the <notification> element and have to register the listener class bean using <notification-listener> as below in Mule Configuration File.
Note: Listener Class is the Spring bean which we created in beans.xml at step 4
xxxxxxxxxx
<notifications>
<notification event="MESSAGE-PROCESSOR" />
<notification-listener
ref="messageProcessorNotifications" />
</notifications>
Listener Class
Testing
Please find the step by step guide, codebase, and video tutorial links provided below for implementing mule server notifications in mule flows.
Guide: https://docs.google.com/presentation/d/1luonPyU1QfOCNNotgv6jR2v3kSt4Xo_0z1JjwKzHhQ8/edit?usp=sharing
Codebase: https://github.com/praneethveni/mule-artifacts/tree/master/message_processor_notifications
Video Tutorial: https://youtu.be/Pb313qfPOJk
Opinions expressed by DZone contributors are their own.
Comments