This blog post will guide you through steps to use SAP Event Mesh in SAP BTP, Cloud Foundry environment and to establish connection between SAP Event Mesh and SAP S/4HANA (on premise) for asynchronous data transfer.

Blog will cover introduction, architecture, enabling SAP Event Mesh and configuration of Message Queues on SAP BTP. We will learn to establish connection between SAP Event Mesh service and SAP S/4 HANA (on premise) system. Then will have a short demo of data transfer between these systems.

SAP Event Mesh

SAP Event Mesh (Earlier known as SAP Enterprise Messaging) is a fully managed cloud service to offer messaging in SAP Business Technology Platform (SAP BTP). This service allows real-time and asynchronous communication between applications through events to develop responsive applications. So these applications can work independently and connect seamlessly through decoupled communication.

Note: SAP Event Mesh is available in SAP BTP, Cloud Foundry environment.

Architecture

Steps

  • Enablement of SAP Event Mesh service on SAP Business Technical Platform
  • Configuration of Message Queue in SAP Event Mesh cockpit
  • Test SAP Event Mesh service using Postman Application
  • Setup Connection between SAP Event Mesh service and SAP S/4 HANA (on premise) system through RFC Destination and OAuth Client Profile
  • Demo of data access in SAP S/4HANA (on premise) system

Enablement of SAP Event Mesh Service on SAP Business Technical Platform:-

Open SAP Business Technical Platform and register yourself, if you have already registered then logon with your user credential.
For SAP Event Mesh service, user can use trial account also by clicking on Go To Your Trial Account.A new trial global account will be created with sub-account trial. Click on sub-account. User can see sub-account specifications(Id, Tenant Id, SubDomain etc.), Cloud Foundry environment, Entitlements (Subscribed services) etc.

Click on Create Space button. Provide Space name as ‘emtrial’ and press Create. User can see newly created Space ‘emtrial’ under trial sub-account.Click on created Space. It will navigate to that space. You can see ‘Service’ tab in left side of page. This tab is having 2 sections – Service Marketplace (SAP provided services for which user has taken subscription), Instances (Instances created by user).

Click on Service Marketplace tab. Search for Event Mesh service. User can see Documentation and available service plan for Event Mesh through clicking on tile.Click on Create button to create a new instance of Event Mesh service. Provide details as below and click on Create button in popup.

Basic Info:-
Service – Event Mesh
Plan.- dev (for trial)
Instance Name – eminstance
Parameters:- {“emname”: “emdemo”, “options”:{“management”: true, “messagingrest”: true}}

User can see newly created instance under Services->Instances in left side of page.Click on Create Service Key to generate service key for Event Mesh instance. Provide Service Key Name as ‘emservicekey’ and click on Create button.New Service Key will be created which will be bound to service instance. Service key will be used to access SAP Event Mesh Service by external systems.Click on View button. A popup will appear and user can see Credentials to access SAP Event Mesh service. Note down clientidclientsecrettokenendpoint and uri which will be required later on. You can download credentials in text format as well.Click on View Dashboard button for instance eminstance. 

 

Configuration of Message Queue in SAP Event Mesh Cockpit:-

On click of View Dashboard button, SAP Event Mesh – Messaging Administration Cockpit is opened in new tab. Under Overview tab, 3 properties are defined.

Connections:- Number of active connections which are accessing Event Mesh instance asynchronously.
Queues:- Number of Message Queues
Number of Messages:- Number of Messages in queueClick on Queues tab in left side of page. Click on Create button. A popup will appear which will ask for Queue NameProvide queue name as ‘demoqueue’ and click on Create button.

Test SAP Event Mesh Service using Postman Application:-

Open Postman application. Create new collection as SAP Event Mesh which will contain HTTP requests related to Event Mesh. There are 4 different types of request.

Token:- POST request which will return access token for message queue. (Success Response Status Code – 200)
Send Message:- POST request which will push message in queue. (Success Response Status Code – 204)
Receive Message:- POST request which will fetch message from queue. (Success Response Status Code – 200)
Acknowledge Message:- POST request which will send acknowledgement to queue that message is consumed successfully from 3rd party system. So queue will delete that message. (Success Response Status Code – 200)

Token:- Create HTTP request as per below parameters. On click of Send button, it will return access_token and token_type in body section.

HTTP Method:- POST
URL:- <tokenendpoint>
Params:- grant_type – client_credentials, response_type – token
Authorization:- 
Basic Authorization, Username – <clientid>, Password – <clientsecret>
Headers:- 
Content-Type – application/x-www-form-urlencodedSend Message:- Create HTTP request as per below parameters. On click of Send button, It will show status code 204 as we are not getting any response back.

HTTP Method:- POST
URL:- <uri from httprest protocol section>/messagingrest/v1/queues/<queue name>/messages
Params:- x-qos – 1, authorization – Bearer <access_token fetched from Token call>
Authorization:- 
No Authorization
Body:- 
Data in JSON, Text or in other format which need to sendGo back to Overview section of SAP Event Mesh – Messaging Administration Cockpit. User can see 1 Connection and 1 Message via Send Message call (by Postman as shown above). Now click on Queues section which shows that there is 1 message in demoqueue.

Receive Message:- Create HTTP request as per below parameters. On click of Send button, It will show status code 200 and user can see response data under body section.

HTTP Method:- POST
URL:- <uri from httprest protocol section>/messagingrest/v1/queues/<queue name>/messages/consumption
Params:- x-qos – 1, authorization – Bearer <access_token fetched from Token call>
Authorization:- 
No AuthorizationAcknowledge Message:- Create HTTP request as per below parameters. On click of Send button, it will show status code 200 and user can see response data under body section.

HTTP Method:- POST
URL:- <uri from httprest protocol section>/messagingrest/v1/queues/<queue name>/messages/<message id>/acknowledgement
Params:- x-qos – 1, authorization – Bearer <access_token fetched from Token call>
Authorization:- 
No AuthorizationNote:- User can copy message id from response of receive message call (Under Header section).Go to Queues section of SAP Event Mesh – Messaging Administration Cockpit. User can see queue name demoqueue along with 0 number of messages. Message is removed from queue.

Setup Connection between SAP Event Mesh Service and SAP S/4 HANA (on premise) system through RFC Destination and OAuth Client Profile:-

Open SAP On-Premise system with SAP Logon. Open SPRO configuration and press SAP Reference IMG. Here we need to perform below operations.

RFC Destination Setup
OAuth Client Profile Creation
OAuth Client Profile Setup

RFC Destination Setup:- Click on SAP Netweaver->Enterprise Event Enablement->Administration->Channel Connection Settings->Manage RFC Destination entry.User can open RFC Destination configuration screen using T-Code SM59 also.We will create a connection to external server. Click on Create icon. Provide destination name as ‘EVENT_MESH_DEMO’ and select connection type as ‘HTTP Connections to External Server’ from drop down.Enter an appropriate description for RFC destination. Provide Host name and Port name under Technical Settings tab. Leave other fields as it is.
Copy URI from HTTPREST protocol section(without ‘https://’ ) in Service Key on BTP for Host Name.Click on Logon & Security tab. Under Security Options, Make SSL as Active and select ANONYM SSL Client (Anonymous) as SSL Certificate. Don’t make any changes for others. No need to make changes for Special Options tab as well.Save this RFC Destination and Click on Connection Test. You can see Status HTTP Response as 200 and Status Text as OK under Test Result. Go to other tabs like Response Header Fields , Response Body, Response Text and see the result.OAuth Client Profile Creation:- Open object navigator using T-Code SE80. Select Local Objects. Right click on Local Object. Under Create icon, User can see various type of development objects. Select on option More which will show option to create OAuth 2.0 Client Profile.Enter Client Profile name as ‘EVENT_MESH_DEMO_PROFILE’ and select Type as ‘HANA_CLOUD_PLATFORM’ from drop down. Click on OK icon. Once new Client Profile is created, Save it.OAuth Client Profile Setup:- Click on SAP Netweaver->Enterprise Event Enablement->Administration->Channel Connection Settings->Manage OAuth Client Setup entry. (or use T-Code OA2C_CONFIG)A  browser window will open with all the existing OAuth Client Profiles for On-Premise System. Click on Create button in header toolbar.In Popup, Select newly created OAuth 2.0 Client Profile from drop down. Keep Configuration Name same as Profile name. Enter OAuth 2.0 Client ID which was copied from Event Mesh service key in SAP Business Technology Platform.Details of Client Profile will be displayed. In Administration tab, Provide Client Secret, Authorization Endpoint and Token Endpoint which are copied from SAP Event Mesh service key. Other fields are auto populated. Do not make any changes for Scopes and Enhancement Settings tabs. Press Save. User can see updated configurations for Client Profile.

 

Demo of data access in On-Premise system:-

We will try to access data of message queue through SAP ABAP executable program. Open T-Code SE38. Enter executable report name as ‘ZRP_READ_EVENT_MESH_DATA’ and click on Create button. In popup, Provide meaningful description for report. Click on Save. An empty report will be created.First, Create EVENT_MESH_DEMO destination object and then create EVENT_MESH_DEMO_PROFILE OAuth 2.0 Client Profile object by accessing static methods of class CL_HTTP_CLIENT. Required code is highlighted in below screenshot.Now set token to authorize access of messages from queueSet x-qos parameter in request header, URI to get message from queue and request method as POST. Now trigger call and receive response from request. This is similar what we have done through Postman application.Get data from response. This data will be in same format(JSON, Text etc.) as of the message we have pushed in queue. Once data is retrieved, we can deserialize into deep structure. Then write your logic to parse deep structure data into desired structure as per requirement.Once data is successfully retrieved, We will send acknowledgement to queue along with message id which was read earlier. Queue will delete that message.For testing, We will push one more message to demoqueue as shown in below screenshot. User can see newly added message in SAP Event Mesh Cockpit.Execute ZRP_READ_EVENT_MESH_DATA report in debugging mode. We can see message data in ls_payload variable in JSON format as highlighted. In lr_data variable, JSON data is parsed in deep structure via deserializing.By expanding deep structure, we can verify data in debugging mode.

Once data is read, Acknowledgement is sent to queue and queue will delete that message. We can see 0 messages in SAP Event MeshYou can see ABAP report code here.

Conclusion

We have explained enablement, creation and configuration of SAP Event Mesh service. Along with this, we have learned how to establish connection between SAP Event Mesh service and SAP S/4HANA (on premises) system through demo.

To get more information on SAP Event Mesh, follow the topic page of SAP Event Mesh.

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x