SAP Event Mesh is the default offering for messaging in SAP Business Technology Platform (SAP BTP). CAP provides out-of-the-box support for SAP Event Mesh, and automatically handles many things behind the scenes, so that application coding stays agnostic and focused on conceptual messaging.
The following guide is based on a productive (paid) account on SAP BTP. It's not supported to use the trial offering of SAP Event Mesh.
Prerequisite: Create an Instance of SAP Event Mesh
SAP Event Mesh documentation recommends to prefix all event names with the service instance's configured namespace, both, when emitting as well as when subscribing to events. If you followed these rules, add corresponding rules to your configuration in package.json to have CAP's messaging service implementations enforcing these rules automatically:
Before deploying to the cloud, you may want to run some ad-hoc tests with a hybrid setup, that is, keep running the CAP services locally, but using the SAP Event Mesh instance from the cloud. Do that as follows:
Configure CAP to use the enterprise-messaging-shared implementation in the reviews and bookstore sample:
The enterprise-messaging-shared variant is for single-tenant usage and uses AMQP by default. Thus, it requires much less setup for local tests compared to the production variant, which uses HTTP-based protocols by default.
Add @sap/xb-msg-amqp-v100 as dependency to reviews and bookstore:
CAP Automatically Creates Queues and Subscriptions
When you run the services with a bound instance of SAP Event Mesh as documented in a previous section, CAP messaging service implementations will automatically create a queue for each receiver process. The queue name is chosen automatically and the receiver's subscriptions added.
A general description of how to deploy CAP applications to SAP BTP's Cloud Foundry, can be found in the Deploy to Cloud* guide. As documented there, MTA is frequently used to deploy to SAP BTP. Follow these steps to ensure binding of your deployed application to the SAP Event Mesh instance.
Add SAP Event Mesh's service instance's name to the requires section of your CAP application's module, and a matching entry to the resources section, for example:
modules:-name:bookstore-srvrequires:-name:<Event Mesh Service Instance - Name>resources:# SAP Event Mesh-name:<Event Mesh Service Instance - Name>type:org.cloudfoundry.managed-serviceparameters:service:enterprise-messagingservice-plan:<Event Mesh Service Instance - Plan>