Technical Articles
[Blog Post] SAP Event Mesh – Consuming S4 events simultaneously in CAP-based applications and SAP Integration Suite
Authors: Ayush Kumar & Vipul Khullar
Previous blog posts in this series:
- [Blog Series] SAP Event Mesh – Deep Dive | SAP Blogs
- [Blog Post] SAP Event Mesh – Event Driven Architecture Explained | SAP Blogs
- [Blog Post] SAP Event Mesh – Single Tenancy & Multi-Tenancy Explained | SAP Blogs
- [Blog Post] SAP Event Mesh – CAP-based implementation of SAP Event Mesh in a Single-Tenant Scenario
- [Blog Post] SAP Event Mesh – Enable SAP Cloud Integration Suite to Consume Messages from SAP Event Mesh Service
- [Blog Post] SAP Event Mesh – S/4HANA On-Premise integration with Event Mesh
Introduction:
In the previous few blogs for this series, we saw how to set up the Event Mesh instance in BTP, communicate between different CAP-based microservices using the SAP Event Mesh service to achieve true asynchronous communication and how the CAP framework facilitates the same, how we can connect the integration suite with Event Mesh, and how to setup connection between S4HANA and Event Mesh on BTP.
In this blog, we will touch upon how we can consume an S4HANA event in a CAP JAVA-based application and simultaneously consume it in SAP Integration Suite as well.
Prerequisite:
To execute the following scenario, you need.
- BTP account (trial account would also work).
- Event Mesh subscription for your subaccount.
- S4HANA connection setup for Event Mesh
Use Case:
This kind of scenario may be required when we are trying to connect more than different sets of applications, typically one could be a legacy system that needs to be connected via SAP Integration Suite and the other one is a CAP-based microservice that can consume events directly.
Scenario:
Sample Scenario
you can find the CAP JAVA-based application that we will be using in the blog here.
The image below shows an Iflow which will be consuming the same events which are consumed by the CAP application simultaneously.
Integration Flow
Steps in CAP Application
- In one of the blogs we have already touched upon how we can communicate between two CAP-based microservices, using that as a reference we will add a few changes to our configuration in the application.yaml file to follow the cloud events standard
cds:
messaging.services:
- name: "messaging" <you can give our you name need not be messaging>
kind: "enterprise-messaging"
format: "cloudevents"
publishPrefix: '$namespace/ce/'
subscribePrefix: '$namespace/ce/'
- now open your S4HANA system and follow the steps mentioned in the previous blog to create outbound bindings.
- Now in your CAP-based application add the following annotation in the handler
@On(service = "messaging", event ={ "sap/s4/beh/purchaseorder/v1/PurchaseOrder/Changed/v1", "sap/s4/beh/purchaseorder/v1/PurchaseOrder/Created/v1"})
public void listen(TopicMessageEventContext context) {
logger.info("---------------------------Reading Payload Emitted by the Event in Same CAP based Microservice----------------------------------------------------");
logger.info("checking if the message if read from SAP Event Mesh {}",context.getIsInbound().toString());
logger.info("reading event id{}",context.getMessageId());
logger.info("reading event data {}", context.getData());
}
- The function above is very straightforward and listens to the creation and change of purchase orders.
- Create a default-env.json file as mentioned in the blog here
- Now run your application
- Create order in S4HANA
Purchase Order
- See the results in the Logs
Reading the Purchase Order in Logs
- See the results in Integration Suite
Consuming the Purchase Order Event In SAP CPI
- Change order in S4HANA
- See the results in the Logs
Changed Event
- See the results in Integration Suite
Changed Event in SAP CPI
Observations
- When you run your application since we have not specified any queue name’s in our application.yaml, CAP automatically creates a queue for us and subscribes to the topic automatically.
- You can create two separate queues for connecting with SAP CPI and CAP Application and subscribe the same topic to both of the queues.
Conclusion
In this blog, we demonstrated a scenario where we can listen to the S4HANA events directly into our CAP Application and SAP Integration Suite Simultaneously.
In the next blog which is going to be the last blog of this series, we will present some of the error-handling capabilities.
Please do like the blog post if you find the content helpful. Also, do share your comments and inputs, if any.