With Getting Started with SAP Enterprise Messaging you would have got a feel of SAP Cloud Platform Enterprise Messaging. One of the features, that makes SAP Cloud Platform Enterprise Messaging completely different than any other Message Broker in the market, is its ability to enable event-driven applications.
An Event can be defined as a significant change in state.
Event-Driven architecture, a software architecture pattern that promotes the production, detection, consumption of and reaction to events.
Monolithic applications have challenges like scalability, reliability and availability and agility. And most probably the root cause of such challenge is high cohesiveness and high coupling of its components. With Micro-services, flexibility comes with the capability of scaling only the needed components and not the application as a whole. Micro-services with Event-Driven Architecture to a great extend solves these challenges and allows building applications capable of dynamic and ever-changing capabilities because of the loosely-coupled architectures where the micro-services are designed to notify each other of changes using events.
And to be able to build such an Intelligent Enterprise, SAP Cloud Platform Enterprise Messaging is supposed to play a major role by helping the event notification between micro-services or two different heterogeneous systems.
SAP Cloud Platform Enterprise Messaging does support Event-Driven programming model. It has the capability to
- Propagate/Distribute Events across distributed landscapes across cloud and on-premise
- Out-of-box event enablement framework for S/4HANA and SFSF standard business objects
- Open standards and protocols-based communication
- Support for SAP Cloud Platform events
Building on this thought process, SAP Cloud Platform Enterprise Messaging has a feature of out-of-box event enablement from S/4HANA or SFSF business objects.
This blog is dedicated to help the developers build an application which requires event handling from S/4HANA.
To be able to consume events from an Event Source, a developer needs to follow the following steps.
1. Create SAP Cloud Platform Enterprise Messaging Instance (including OAuth2.0 Client ID and Secret) to be used by Eventing
2. Create S/4 Communication System and Communication Arrangement
3. Maintain Event Topics for a Channel
4. Queue Subscription to the Event Topic Pattern
- You already have an SAP Cloud Platform Enterprise Messaging instance configured in your CF account. Follow Getting Started with SAP Enterprise Messaging, if you are yet to.
- SAP Cloud Connector (if needed) and Destination configuration to access S/4HANA event catalog from CF is already completed.
Once we have the SAP Cloud Platform Enterprise Messaging Instance available, we need to complete following configurations to enable out-of-box Eventing support from S/4HANA using SAP Cloud Platform Enterprise Messaging.
|Make the SAP Cloud Platform Enterprise Messaging Instance ready for Eventing|
Select the newly created SAP Cloud Platform Enterprise Messaging instance,
- Select the Service Key.
- Click on Create Service Key.
- Provide any name.
- Make a note of the client ID, client secret, token endpoint and base URL, then use these parameters to create a communication arrangement.
The newly created Service Key contains following information:
- clientId: This ID is used to log on to the Enterprise Messaging endpoint from outside
- clientsecret: This is the password to be used with the clientId.
- uri: These are the endpoints provided by Enterprise Messaging. From this
we can get the hostname and path needed for the configuration of the
Communication Arrangement on the S/4 system.
Note: SAP Cloud Platform Enterprise Messaging provides several endpoints supporting different protocols (e.g. AMQP1.0 and MQTT 3.1.1 over WebSocket and REST).
|Configuring Communication System and Communication arrangement on S/4HANA system|
Logon to S/4 System with an Administrator user:
Navigate to Communication Management area.
General overview of the necessary steps described in this guide:
- Create Communication System (like defining a RFC destination)
- Create Communication User to access the S/4 system from the outside – this will be done during creation of communication system
- Create Communication Arrangement
Select the Communication Systems tile and click on New.
Provide any unique System ID and System Name and click Create.
The newly created Communication System is being displayed. Scroll down to the Technical Data section and provide the General configuration settings:
- Host Name is on…FACTORY/TRIAL: enterprise-messaging-messaging-gateway.cfapps.eu10.hana.ondemand.com
Or you can find the information from the Service Instance: Eventing – Service Keys (without https:// part)
Under OAuth 2.0 Settings provide:
- tokenendpoint replacing the last path segments with /oauth/authorize
- tokenendpoint as in the Service Key information ending with /oauth/token
In the section User for Inbound Communication click the Add button.
The Inbound Communication user is needed to access the S/4 system from the outside.
If you already have an Inbound Communication User available, you can re-use the same.
Otherwise create a new user by clicking on New User.
- Provide a unique User Name and a Description
- Either provide a password or click on Propose Password
- Save the proposed password to a save place, there is no other way to retrieve this password
- Complete the user creation by clicking on Create
- The user and password are needed when retrieving the Event Catalogs from the S/4 system
The newly created Inbound Communication User is automatically selected in the dialog.
Click OK to assign this user.
In the section User for Outbound Communication click the Add button.
The Outbound Communication User is required to connect from the S/4 system to the Enterprise Messaging on CF. The required credentials have been generated when creating the Service Key on CF.
- Authentication Method select OAuth 2.0
- OAuth 2.0 Client ID from Service Instance: Eventing – Service Keys
- Client Secret from Service Instance: Eventing – Service Keys
- Create the New Outbound User
- Finally Save the Communication System
Let us set up the Communication Arrangement.
In Home screen select the Communications Arrangements tile
to create a new Communication Arrangement. Click the New button and provide the following data:
- Scenario: select SAP_COM_0092 from the value help
- Provide any unique Arrangement Name
- Click Create
Under Common Data select previously created Communication System from the value help → Inbound Communication, Inbound Services and Outbound Services get filled automatically.
Fill in the Additional Properties:
- Give any name for the Channel
- Give any Description for the Channel
- Topic Space: best practice is to use system name, to see where events are coming from. The Topic pattern of event payload will be sent to SAP Cloud Platform Enterprise Messaging service instance as
<topic space>/<event path>
- QoS (Quality of Service) = 1 (At least once)
- Reconnect Attempts: any amount of reconnect attempts in case of a connection error
- Reconnect Wait Time: idle time between 2 reconnection tries
Finally, the details for the Outbound Services need to be provided:
As Path provide: /protocols/mqtt311ws
Click Check Connection
Save the Communication Arrangement.
The Check Connection will try to check if a connection(by creating web-socket) can be established between S/4 and SAP Cloud Platform CF.
In the Inbound Services section you can find the URL to call the Event Browser Service.
|Maintain Event Topics for a Channel|
Logon to S/4 Backend system with a user that has access to
Implementation Cockpit → Manage Your Solution
Click on Manage Your Solution
- In the filter provide messaging
- from the results list select the entry called Event Handling
Click on Configure for the entry called Maintain Event Topics
Click the value help to choose your Event Channel from the list of
Confirm your selection by clicking the green check mark.
- Select New Entries
- Select the first empty line of the table and use the value help to
open the list of available Topics.
- Select any of the Topics you want to add to your Channel.
You can choose between specific Topics only or by selecting sub paths.
- Click on Save
- Click on Exit
|Setup Queue Subscription to consume Event Topics to be exposed by this channel.|
- Open the SAP Enterprise Message Service instance Dashboard.
- Select Queue Subscriptions in the Left Menu.
- Provide the Queue Name and the Topic Name or Pattern which you have configured in the S/4HANA system.
Based on the configuration done in the S/4HANA system, the queue contains the messages with the topic name and pattern.
And we are done !!!!.
Yes, the setup steps are done. And we are ready for the consumption.
Now just subscribe your application to the queue, and you are ready to get notified (either in AMQP or in REST protocol) when a message comes to the queue.
A Picture is like thousand words. And let me finish this blog, with the below picture which highlights the E2E story of out-of-box event handling support of SAP Cloud Platform Enterprise Messaging with S/4HANA.