In this example, Our goal is to create events on SAP Event Mesh through CAP App using Event Mesh Destination.
We will be following below steps-
- 1. Create Instance of Event Mesh on any Cloud Foundry Space
- 2. Create Queue and Subscription on Event Mesh
- 3. Create Event Mesh Destination on Subaccount
- 4. Create CAP App
- 5. Add destination configuration on package.json file
- 6. Define services of the app on srvice.cds file
- 7. Define services custom logic on srvice.js file
- 8. Add Hana, mta file, xsuaa and approuter file
- 9. Check the Destination binding mta.yaml file
Step 1 - Create Instance of Event Mesh on any Cloud Foundry Space
On SAP BTP Cockpit, go to the cloud foundry space on which you wants to create Event Mesh Instance.
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
You can follow the similar way like we created for our application -
Step 3 - Create Event Mesh Destination on Subaccount
You can create service key on event mesh instance and use its credentials while creating the Destination.
You can refer below details -
Destination Name :- Any Name (in our case, we are using - EVENT_MESH_DEST_POC13App)
Type :- HTTP
URL :- uri from event mesh instance service key + /messagingrest/v1/topics/ + topic name
remember - replace / with %2f on topic name
since our topic was - companyName/subaccountName/pocem/cap/topic
after replacing / with %2f - companyName%2fsubaccountName%2fpocem%2fcap%2ftopic
Authtication :- OAuth2ClientCredentials
Proxy Type :- Internet
client Id :- client id from uaa section of event mesh instance service key
client secret :- client secret from uaa section of event mesh instance service key
token service url :- url from uaa section of event mesh instance service key + /oauth/token
Step 4 - Create CAP App
Follow below commands to create CAP app -
These dependencies are needed to consume Destination on CAP App.
In our case, the app name is poc13app
Step 5 - Add destination configuration on package.json file
In package.json file, add the below destination configuration after script or private key to connect connect with destination.
In our case package.json file looks like below -
Step 6 - 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 7 - Define services custom logic on srvice.js file
In your srv folder, create service.file file and define the custom logic like below-
Step 8 - Add Hana, mta file, xsuaa and approuter file
use the below command for the same -
Step 9 - Check the Destination binding mta.yaml file
Make sure the Destination service binding 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 -
And it is done, you can deploy your app and test it. !!!