In event-driven applications built with SAP CAP, it’s often necessary to track and manage the flow of events across various topics. The CDS Event Monitoring Plugin provides a practical solution for recording, viewing, and retrying events. It integrates directly with CAP projects, storing event data in a CDS entity and exposing it via a service that can be customized as needed.
This post gives an overview of what the plugin does, how to set it up, and how to extend it for specific requirements.
Link: cds-event-monitoring
Monitors multiple messaging topics
Stores event payloads in a CDS entity (customizable)
Provides a CDS service (EventMonitoringService) with actions for resending messages
Supports dead-message queue (DMQ) monitoring
Includes optional event filtering and retention settings
To install the plugin, run:
npm add cds-event-monitoring
Then, configure it in your .cdsrc.json or package.json under the cds.requires section:
"cds": {
"requires": {
"event-monitoring": {
"retentionInDays": 7,
"topics": ["my/namespace/topic"],
"dead-message-queues": ["my/namespace/dmq"]
}
}
}
Configuration Options:
Option | Type | Description |
topics | Array of Strings | List of messaging topics to monitor |
retentionInDays | Integer | Retains event data for the given number of days; deletion is triggered when new data arrives |
ignoreIdenticalEvents | Boolean | If true, repeated events with the same payload are ignored |
dead-message-queues | Array of Strings | Optional list of DMQs to consume and track |
The plugin provides a CDS service called EventMonitoringService. This exposes the stored events and allows users to resend them or push new messages to topics.
service EventMonitoringService {
action resendAll(topic : String, startTimestamp : Timestamp, endTimestamp : Timestamp);
action resendDeadMessageQueue(queue : String);
action sendToTopic(topic : String, message : LargeString);
entity Events as projection on EventData actions {
action resend();
action resendToTopic(topic : String);
};
}
These actions make it easier to manually or programmatically manage event flow.
The service can be extended to include additional roles or logic. For example:
using {EventMonitoringService} from 'cds-event-monitoring/srv';
extend EventMonitoringService with @(requires: 'admin');
You can also override the service implementation in JavaScript or TypeScript:
const cds = require('@sap/cds');
const EventServiceHandler = require('cds-event-monitoring/srv');
module.exports = class EventServiceExt extends EventServiceHandler {
async init() {
const messaging = await cds.connect.to('messaging');
// Extend messaging logic
messaging.on('*', (msg) => {
const { data, event } = msg;
console.log(data);
console.log(event);
});
return super.init();
}
};
This allows you to inject custom behavior without modifying the plugin itself.
If you want to store specific fields in separate database columns (for example for searching purposes) you can do so, by extending the cds entity EventData
using { event.monitoring.EventData } from 'cds-event-monitoring/db';
extend EventData with {
description : String;
}
As long as the incoming event contains a matching field in the payload:
{
"data": {
"description": "Sample description"
}
}
…the new field will be filled automatically.
The plugin includes basic Fiori annotations for the Events entity. These can be used to build a monitoring UI using standard Fiori Elements. You can extend the service with additional Fiori Annotations. A working example is available in the testProject/app folder in the repository.
If you're working with messaging in a CAP-based project, give the CDS Event Monitoring Plugin a try. It's straightforward to set up and can help you track and manage events more effectively during development and in production scenarios.
As the plugin is still at an early stage, I'm looking forward to improving it. If you run into any issues, have suggestions for improvement, or can think of a feature that would make your job easier, please open a bug or contribute directly via the GitHub repository.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
9 | |
8 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
5 |