In this example, Our goal is to create events on SAP Event Mesh through CAP App.
We will be following below steps-
- 1. Create Instance of Event Mesh
- 2. Create Queue and Subscription on Event Mesh
- 3. Create CAP App to create Event on Event Mesh
- 4. Add Event Mesh configuration on package.json file
- 5. Define services of the app on srvice.cds file
- 6. Define services custom logic on srvice.js file
- 7. Add Hana, mta file, xsuaa and approuter file
- 8. Check the Event Mesh Instance binding on mta.yaml file
- 9. Check the xs-security.json file configuration
Step 1 - Create Instance of Event Mesh
On SAP BTP Cockpit, go to the cf space on which you will be deploying your CAP Application.
For our application, we are creating Event Mesh instance - pocem
We are using emname - pocem and similar for namespace - pocem
while creating the Event mesh instance, we have used below json -
Step 2 - Create Queue and Subscription on Event Mesh
Step 3 - Create CAP App to create Event on Event Mesh
Follow below commands to create CAP app -
In our case, the app name is poc13app
Step 4 - Add Event Mesh configuration on package.json file
In package.json file, add the below event mesh configuration after script or private key to connect connect with Event Mesh.
In our case package.json file looks like below -
Step 5 - Define services of the app on srvice.cds file
In your srv folder, create service.cds file and define the event and action on the serivce like below-
Step 6 - Define services custom logic on srvice.js file
In your srv folder, create service.file file and define the custom logic like below-
Step 7 - Add Hana, mta file, xsuaa and approuter file
use the below command for the same -
Step 8 - Check the Event Mesh Instance binding on mta.yaml file
Make sure the Event Mesh Instance is defined properly on mta.yaml file under resources section to create proper binding like below -
And the same is defined under modules requires on mta.yaml file -
Note - We are using name pocem because our event mesh instance has the name pocem
In our case, mta.yaml file looks like below -
Step 9 - Check the xs-security.json file configuration
It gives permission for SAP Event Mesh and your CAP app to talk to each other securely.
Make sure it has the configuration like below -
Explaination of above statement -
This below scope says - Event Mesh is allowed to call my application.
This below statement allows your CAP app to manage Event Mesh like Create queues, Create subscriptions, Manage messaging configuration
This below statement gives these permissions directly to your CAP application.
And it is done, you can deploy your app and test it. !!!