Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 
Authorsak47_ & vipul.khullar

Previous blog posts in this series:



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.


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.



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

- 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) {"---------------------------Reading Payload Emitted by the Event in Same CAP based Microservice----------------------------------------------------");"checking if the message if read from SAP Event Mesh {}",context.getIsInbound().toString());"reading event id{}",context.getMessageId());"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



  • 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.


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.