SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

4 - Publish and Subscribe to Events

Dive deeper into the message exchange, still by using the UI in AEM, and also explore a different section through which you can exchange messages.

Overview

🎓 intermediate 30 min. SAP BuildIntermediateSAP Integration SuiteSAP Build Process AutomationSAP Business Technology Platform

You will learn

  • โœ”What are topics, queues and subscriptions
  • โœ”How to create a queue
  • โœ”How to add subscriptions to a queue
  • โœ”How to send and receive messages using Try Me! page in the event broker service
Created by February 12, 2025
Contributors

Prerequisites

Prerequisites

  • You have completed the previous tutorial for the event-based processes CodeJam, Explore SAP Integration Suite, advanced event mesh.
  • You have received the participants handbook, which contains systems and credentials you will need. The instructor will provide this to you.

Steps

Intro

In a previous tutorial, we learned more about event-driven architecture, so we are now familiar with the basic UI elements in SAP Integration Suite, advanced event mesh (AEM).

In this tutorial, we will dive deeper into the message exchange, still by using the UI in AEM and we will also explore a different section through which you can exchange messages. Before we get to the exercise, we might need to expand a bit on some concepts.

Let’s get started.

Try Me! with Queue functionality
Try Me! with Queue functionality

Step 1 Topics
โ€”

In a previous exercise, we mentioned that a topic is a means by which a publisher classifies a message. A topic tells us what type of message we will receive if we subscribe to that topic.

In essence, it is a string that is composed of one or more levels. Each level is separated by a forward slash (/) and the levels can be anything. This is commonly known as topic-level granularity. The granularity allows for more targeted and efficient information exchange.

Instead of having a single topic for all updates on a business object in a complex system (/BusinessPartner), the system can have distinct topics for different types of updates on a business object (/BusinessPartner/Created, /BusinessPartner/Updated, /BusinessPartner/Deleted).

There is no specific schema/specification on how you need to structure your topic string but you do find that patterns are established within a system. Let’s get familiar with the structure of a topic by “dissecting” a real-world topic.

Below we can see a topic on which an SAP S/4HANA Cloud system will publish a Business Partner message.

Example: default/sap.s4/S4D/ce/sap/s4/beh/businesspartner/v1/BusinessPartner/Created/v1:

  • default/sap.s4/S4D: System information.
  • /ce: CloudEvent. We know that all events published by an SAP S/4HANA Cloud system follow the CloudEvent specification
  • /sap/s4: This is coming from an SAP S/4HANA system.
  • /beh/businesspartner/v1/BusinessPartner: Information of the business object that we will be receiving.
  • /Created: This is the action that took place in the source system. In this case, it is notifying us that a Business Partner was created. Many actions can take place in a system, for example, /Updated or /Deleted. In other cases, if we were dealing with a business object like a Purchase Order, there could be an event raised when it is /Cancelled or /Rejected.
  • /v1: Version of the message. If a new version of the message is made available โ€“ adding new fields to the payload โ€“ then this will change.

Now, by knowing the topic on which a message type will be published, we can create a consumer program/service that subscribes to the topic directly and processes the messages sent to it. Generally, you can subscribe to a topic by specifying the entire topic string when establishing the connection โ€“ for example, default/sap.s4/S4D/ce/sap/s4/beh/businesspartner/v1/BusinessPartner/Created/v1.

But what if we want to subscribe to all actions (Created, Updated, Deleted) that occur on a BusinessPartner object?

Luckily, in the case of SAP Integration Suite, advanced event mesh, we can subscribe to the topic by using wildcards (*). For example, by subscribing to the topic default/sap.s4/S4D/ce/sap/s4/beh/businesspartner/v1/BusinessPartner/*/v1 we will be able to get all messages for different actions (Created, Updated, Deleted) whose version is v1.

In AEM, the > character can be used at the last level of a subscription to indicate a “one or more” wildcard match for any topics โ€“ for example, by subscribing to the topic default/sap.s4/S4D/ce/sap/s4/beh/> will bring all objects that are published under that prefix, independent of type, action, and version.

In the example above we can see how the topic level granularity can allow a consumer program/service to subscribe only to the information it needs.

Learn more about wildcard characters in topic subscriptions: https://help.pubsub.em.services.cloud.sap/Messaging/Wildcard-Charaters-Topic-Subs.htm

If our consumer program/service subscribes to a topic, we will receive all messages for that topic subscription. That said, a direct topic subscription lasts only as long as the consumer is connected. The problem here is that our consumer needs to be online to receive a message. If the consumer becomes unavailable then we will end up losing the message.

In some scenarios, this is unacceptable and we need to ensure that we receive and process all messages published. Fortunately, there is a mechanism to retain messages without the need for a consumer service to be online 100% of the time. Then, the consumer can process the messages asynchronously or whenever it is available. Enter Queues.

Step 2 Queues
+
Step 3 Topic subscription
+
Step 4 Topic endpoint
+
Step 5 Publish an event
+
Step 6 Subscribe to an event
+
Step 7 Create a Queue
+
Step 8 Subscribe to a Queue
+
Step 9 Create a Business Partner in the simulated SAP S/4HANA Cloud system
+
Step 10 Further study
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 10
1. Topics 2. Queues 3. Topic subscription 4. Topic endpoint 5. Publish an event 6. Subscribe to an event 7. Create a Queue 8. Subscribe to a Queue 9. Create a Business Partner in the simulated SAP S/4HANA Cloud system 10. Further study

Learn more →