Skip to Content
Technical Articles
Author's profile photo Mahesh Kumar Palavalli

Sending Messages from ABAP, BTP Environment to Cloud integration (CPI) using Event Mesh

This blog post showcase a small example of how to send events/messages from ABAP, BTP environment to SAP CPI using Event Mesh, all using the trial account. There can be many different scenarios that can use this example, for instance, if we have a side-by-side extension using ABAP, BTP environment, and to trigger a CPI flow for workflow or something else, we can use this approach.

 

Background

I recently gave a presentation in an SAP Community event about Event Mesh. For that, I took an example of sending messages from ABAP, BTP environment to CPI (Cloud Integration) using the Event mesh. BTW, I also took help from my friend J Pavan Kumar to do this :). ( It’s more fun if you collaborate with someone and present than doing it alone, so give it a try once 🙂 ) So now I thought of writing about it as a simple blog post and here I am.

 

Creating the Event Mesh Instance:

For creating an event mesh instance(trial) with Queues & topics, follow the blog post (Appendix: 4) from Carlos Roggan

https://blogs.sap.com/2020/03/03/sap-cloud-application-programming-model-and-enterprise-messaging-1-intro/

or the SAP Help

https://help.sap.com/viewer/bf82e6b26456494cbdd197057c09979f/Cloud/en-US/7e504322652d4791ade0ca2bbc5a6443.html

 

Create the service key for the instance, which we will use for communication with Event mesh, from ABAP & CPI.

Now create a Queue: queue1 and Topic (Queue Subscription) for that queue, topic1.

 

Preparing the ABAP, BTP environment:

in ABAP, BTP env., check the below blog post from Rich Heilman

https://blogs.sap.com/2021/05/06/how-to-leverage-the-sap-event-mesh-from-sap-btp-abap-environment/

https://github.com/SAP-samples/cloud-abap-event-mesh-api.git

 

Install it in ABAP cloud using the abapGit plugin,

then go to the class: zcl_ems_api and update the constants with the values from the service key(event mesh).

Now create a test class that inherits the interface: if_oo_adt_classrun and call the ems API class method: publish_message to topic as shown below:

In productive scenarios, we usually call this method from the save-sequence in the RAP service, to send the create/update/delete event data to the event mesh (e.g., in side-by-side extension).

 

Getting ready to receive the messages in CPI:

I will just create a dummy flow to receive the messages. The only important thing here is to configure the receiver correctly.

The receiver should be of type “AMQP”. and in the connection tab, provide the details from the event mesh service key, (amqp segment)

along with that maintain the credentials as well.

 

After that configure the topic details in the processing tab.

 

that’s it, our basic CPI flow is also done, you can enhance it with the further process as per the business.

for more information on AMQP sender/receiver, check the below post:

https://blogs.sap.com/2019/11/20/cloud-integration-connecting-to-external-messaging-systems-using-the-amqp-adapter/

 

Now when we execute the test ABAP program that was created in step1, we can see the CPI flow triggered in the message monitor.

(note: ignore the status: ‘retry’, it’s a mistake from my side in the integration flow, too lazy to correct it 🙁 )

 

That’s the small example pavan and I showed at the community event. and of course, we use destinations to connect, instead of hardcoding all those information in the productive systems.

Share your thoughts or best practices or any added information in the comments 🙂

 

Cheers!

Mahesh

Assigned tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Lars Hvam
      Lars Hvam

      sidenote: ABAP supports native AMQP since 7.52(?)

      https://help.sap.com/viewer/05d041d3df1a4595a3c45f57c15e2325/202009.002/en-US/e856ed184feb4eb9ae9b57fe7f141fec.html

      But I don't think its possible to use in ABAP BTP as of now

      Author's profile photo Mahesh Kumar Palavalli
      Mahesh Kumar Palavalli
      Blog Post Author

      Thanks for sharing this info.. When i checked some time back, I couldn't find a way to have a amqp wait instance (running independently in background?) for receiving messages & calling the respective class continuously, is it something possible now? or we just have to write an endless loop and run it as a background joB?

      Author's profile photo Lars Hvam
      Lars Hvam

      I think deamons, https://blogs.sap.com/2021/09/22/create-a-simple-daemon-in-abap/, are intended for that usecase

      There is also an example in https://github.com/se38/abapMQDaemons

      But I've not tried writing one yet 🙂