|
| 1 | +--- |
| 2 | +parser: v2 |
| 3 | +author_name: Antonio Maradiaga |
| 4 | +author_profile: https://github.com/ajmaradiaga |
| 5 | +auto_validation: true |
| 6 | +time: 30 |
| 7 | +tags: [ tutorial>intermediate, software-product>sap-build, software-product>sap-integration-suite, software-product>sap-build-process-automation, software-product>sap-business-technology-platform] |
| 8 | +primary_tag: software-product>sap-build |
| 9 | +--- |
| 10 | + |
| 11 | +# Forward Events to SAP Build Process Automation |
| 12 | + |
| 13 | +<!-- description -->Learn how we can configure forwarding events to a particular SAP Build Process Automation tenant, so that we can later create processes that can be triggered by those events. |
| 14 | + |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | +- You have access to an SAP Integration Suite, advanced event mesh tenant and an SAP Integration Suite tenant. |
| 18 | + |
| 19 | +## You will learn |
| 20 | +- How to configure REST Delivery Points in SAP Integration Suite, advanced event mesh |
| 21 | +- How to forward messages from a queue to a REST consumer |
| 22 | + |
| 23 | + |
| 24 | +## Intro |
| 25 | +Now that we are familiar with the SAP Integration Suite, advanced event mesh, how we can publish and subscribe to events, and how we can exchange messages using an event broker service, we will tackle a common business scenario: forwarding events to an application that exposes a REST endpoint. In this particular case, we will forward events to SAP Build Process Automation, so that we can trigger a business process in it. For example, we may want to forward the BusinessPartner created event from SAP S/4HANA Cloud. |
| 26 | + |
| 27 | +There are scenarios where the target system/application can't consume messages directly from an event broker but we still want these systems/applications to be part of our event-driven world and react to events as they are produced. Fortunately, some of these systems might expose APIs (REST endpoints) through which we can notify them of an event. |
| 28 | + |
| 29 | +For these cases, we can leverage REST Delivery Points to forward messages from a queue to that system. For example, the integration we are about to configure between SAP S/4HANA Cloud and SAP Build Process Automation goes through an event broker service in SAP Integration Suite, advanced event mesh. In AEM, we end up configuring a [REST Delivery Point](https://help.sap.com/docs/event-mesh/event-mesh/manage-webhook-subscriptions) to [forward the events received and start a process](https://help.sap.com/docs/build-process-automation/sap-build-process-automation/create-event-triggers) in SAP Build Process Automation. |
| 30 | + |
| 31 | +> You can check out this [SAP Tech Bytes: SAP S/4HANA Cloud + SAP Integration Suite, AEM + SAP Build Process Automation](https://community.sap.com/t5/application-development-blog-posts/sap-tech-bytes-sap-s-4hana-cloud-sap-integration-suite-aem-sap-build/ba-p/13706661). |
| 32 | +
|
| 33 | +By the end of this tutorial, we will achieve a communication scenario like the one below. |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +### Create a service key for the SAP Build Process Automation instance |
| 38 | + |
| 39 | +SAP Integration Suite, advanced event mesh will be forwarding events to SAP Build Process Automation. In order to configure the secure connection between these services, we will need to create a service key for SAP Build Process Automation, which will be used by AEM to connect and deliver the event to SAP Build Process Automation service. |
| 40 | + |
| 41 | +1. In the SAP BTP cockpit, go to **Instances and Subscriptions**. |
| 42 | + |
| 43 | + Under **Instances**, click the 3 dots next to the SAP Build Process Automation instance, e.g., **spa-service** in the screenshot below, and select |
| 44 | + |
| 45 | +  |
| 46 | + |
| 47 | +2. In the dialog, give the key a name, e.g., **spa-key**. |
| 48 | + |
| 49 | +  |
| 50 | + |
| 51 | + Click **Create** |
| 52 | + |
| 53 | +3. After the key is created (it will take about half a minute), click he 3 dots next to the key and download the key. |
| 54 | + |
| 55 | +  |
| 56 | + |
| 57 | + Keep it in a safe place. You will need it later in the tutorial. |
| 58 | + |
| 59 | + |
| 60 | +### REST Delivery Points (RDP) |
| 61 | + |
| 62 | +A REST delivery point (RDP) is a provisioned object on an event broker service that facilitates message delivery to REST consumers. The RDP can be bound to message queues to deliver messages from those queues to REST consumers. The RDP maintains a list of REST consumers, which are identified by their remote connection information. |
| 63 | + |
| 64 | +For this tutorial, we will use an event broker service in AEM and in it, we can create a new queue or reuse an existing queue. In the steps below we will be using a queue named `EDP_BP_Created_[SAPCommunityDisplayName]` but this can be something different on your end. |
| 65 | + |
| 66 | +> To learn how to configure a queue in SAP Integration Suite, advanced event mesh, you can check out this tutorial 👉 [Queues and subscriptions in SAP Integration Suite, advanced event mesh](../pubsub-queues-subscriptions/pubsub-queues-subscriptions.md) |
| 67 | +
|
| 68 | +The queue will need to be subscribed to the business event that you are interested in sending to SAP Build Process Automation, e.g. the `default/sap.s4/S4D/ce/ce/sap/s4/beh/businesspartner/v1/BusinessPartner/Created/v1` topic which is where an Business Partner created event will be published. |
| 69 | + |
| 70 | +> Note that in order for SAP Build Process Automation to be able to process the event, the event needs to follow the [CloudEvents specification](https://cloudevents.io). |
| 71 | +
|
| 72 | + |
| 73 | +### Create a REST Delivery Point |
| 74 | + |
| 75 | +Now that we know what a REST Delivery Point is, we are ready to create a REST Delivery Point (RDP) to forward messages from the queue to a REST consumer. |
| 76 | + |
| 77 | +1. Inside the event broker service where the queue exists, click **Open Broker Manager**. |
| 78 | + |
| 79 | +2. Click **Clients** on the left-side menu. |
| 80 | + |
| 81 | + Click **REST**. |
| 82 | + |
| 83 | +  |
| 84 | + |
| 85 | +3. Click **+ REST Delivery Point**. |
| 86 | + |
| 87 | +  |
| 88 | + |
| 89 | + Enter a name, e.g., `EDP-SBPA-BPCreated-[SAPCommunityDisplayName]`. |
| 90 | + |
| 91 | +  |
| 92 | + |
| 93 | + Click **Create**. |
| 94 | + |
| 95 | + A simple configuration form will appear. No need to modify anything here – **Do not enable the RDP yet**, that is, leave the toggle button off. |
| 96 | + |
| 97 | + Click **Apply**. |
| 98 | + |
| 99 | +  |
| 100 | + |
| 101 | +4. Once created, go to the RDP details page by clicking on the name of the RDP. |
| 102 | + |
| 103 | +  |
| 104 | + |
| 105 | + You will see that there isn't much here yet, as we haven't configured the REST consumer details. We will do this now. |
| 106 | + |
| 107 | +  |
| 108 | + |
| 109 | +### Configure the REST consumer |
| 110 | + |
| 111 | +Now that we've created a REST Delivery Point, we have to specify where we want events sent. |
| 112 | + |
| 113 | +1. Navigate to the **REST Consumers** tab. |
| 114 | + |
| 115 | +2. Click **+ REST Consumer**, and enter the name, e.g., `SBPA_[SAPCommunityDisplayName]`. |
| 116 | + |
| 117 | + Click **Create**. |
| 118 | + |
| 119 | +  |
| 120 | + |
| 121 | + A configuration form will be displayed. |
| 122 | + |
| 123 | +3. Enter the details from the SAP Build Process Automation service key created in the previous step. |
| 124 | + |
| 125 | + >**IMPORTANT:** Do not enable the REST Consumer yet – leave the toggle button off. |
| 126 | +
|
| 127 | + Enter the following: |
| 128 | + |
| 129 | + | Field | Value | |
| 130 | + | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
| 131 | + | *Host* | Value from service key `.endpoints.api`, e.g.`spa-api-gateway-bpi-us-prod.cfapps.[region].hana.ondemand.com` | |
| 132 | + | *Port* | `443` | |
| 133 | + | *HTTP Method* | `POST` | |
| 134 | + | *TLS Enabled* | `Yes` | |
| 135 | + | *Authentication Scheme* | `OAuth 2.0 Client Credentials` | |
| 136 | + | *Client ID* | Value from service key `.uaa.clientid`, e.g. *sb-VQ18I1VS-3226-5LF1-JVWV-760D08FHP857-3ok534d4-8562-632j-436w-0j5b0n8r4d0l!b139588 \| eventing-xsuaa-broker!b####* | |
| 137 | + | *Client Secret* | Value from service key `.uaa.clientsecret` | |
| 138 | + | *Token Endpoint URL* | Concatenate the value from service key `.uaa.url`, e.g. *https://[host].authentication.[region].hana.ondemand.com*, and `/oauth/token` | |
| 139 | + | *Token Expiry Default* | `3600` | |
| 140 | + |
| 141 | +4. Click **Apply**. |
| 142 | + |
| 143 | +  |
| 144 | + |
| 145 | +The newly created REST consumer will be listed in the REST Consumers tab. Now we need to configure the queue that we will bind to our RDP. Events in this queue will be forwarded. |
| 146 | + |
| 147 | + |
| 148 | +### Configure Queue binding |
| 149 | + |
| 150 | +Now that we have a REST consumer configured, we can proceed to bind a queue and configure the binding for our REST Delivery Point. All events received by the queue will be then forwarded to the REST consumer we configured, once enabled. |
| 151 | + |
| 152 | +1. Navigate to the **Queue Bindings** tab. |
| 153 | + |
| 154 | +2. Click **+ Queue Binding**. |
| 155 | + |
| 156 | + Select the queue you previously created, e.g., `EDP_BP_Created_[SAPCommunityDisplayName]`. |
| 157 | + |
| 158 | +  |
| 159 | + |
| 160 | +3. Click **Create**. |
| 161 | + |
| 162 | +4. A simple configuration form will be displayed. |
| 163 | + |
| 164 | + In the **Post Request Target** field, you need to enter the path where we can send events to SAP Build Process Automation (`/internal/be/v1/events`). Notice that you will need to include the `/` at the beginning of the value. |
| 165 | + |
| 166 | + Enter the following details: |
| 167 | + |
| 168 | + | Field | Value | |
| 169 | + | --------------------------- | ------------------------ | |
| 170 | + | *Post Request Target* | `/internal/be/v1/events` | |
| 171 | + | *Request Target Evaluation* | None | |
| 172 | + | *Replace Target Authority* | No | |
| 173 | + |
| 174 | + Click **Apply**. |
| 175 | + |
| 176 | +  |
| 177 | + |
| 178 | +The newly created queue binding will be listed in the **Queue Bindings** tab. Now we need to configure a request header that is required by SAP Build Process Automation. |
| 179 | + |
| 180 | + |
| 181 | +### Configure Request Headers |
| 182 | + |
| 183 | +Now that we have a Queue binding configured, we need to set some request headers which are specific to SAP Build Process Automation. |
| 184 | + |
| 185 | +1. In the **Queue Bindings** tab, select your queue binding. |
| 186 | + |
| 187 | +  |
| 188 | + |
| 189 | +2. Navigate to the **Request Headers** tab. |
| 190 | + |
| 191 | +  |
| 192 | + |
| 193 | +3. You will create 2 headers. |
| 194 | + |
| 195 | + For each, you will click **+ Request Header**, enter the header name, then the header value, and then click **Apply**. |
| 196 | + |
| 197 | + Create the following headers: |
| 198 | + |
| 199 | + | Header Name | Header Value | |
| 200 | + | ------------------------ | ------------------------------ | |
| 201 | + | `Content-Type` | `application/cloudevents+json` | |
| 202 | + | `WebHook-Request-Origin` | `aem` | |
| 203 | + |
| 204 | +  |
| 205 | + |
| 206 | +> In the request headers configured we specified the Content-Type header. We can see that its value is _application/cloudevents+json_. This is because SAP Build Process Automation expects events that follow the CloudEvents specification. |
| 207 | +
|
| 208 | +Now that we've created the request headers, we are ready to enable the REST consumer and the RDP. |
| 209 | + |
| 210 | +### Enable the REST Consumer and RDP |
| 211 | + |
| 212 | +We've configured the REST consumer and the queue binding, we can enable the REST consumer and the RDP. |
| 213 | + |
| 214 | +First, let's see all the objects that we've configured. |
| 215 | + |
| 216 | +1. Navigate back to the main page for your RDP. |
| 217 | + |
| 218 | + Select the **Summary** tab. Here you will see all the objects and their status. Notice that the only object in an operational state is the queue we created at the beginning of the exercise. |
| 219 | + |
| 220 | +  |
| 221 | + |
| 222 | +2. Navigate to the **REST Consumers** tab, and click the name of your REST consumer, e.g., `SBPA_[SAPCommunityDisplayName]`. |
| 223 | + |
| 224 | +  |
| 225 | + |
| 226 | +3. Click **Edit** on the top right. |
| 227 | + |
| 228 | +  |
| 229 | + |
| 230 | + Enable the REST consumer by toggling the **Enabled** setting. |
| 231 | + |
| 232 | + Click **Apply**. |
| 233 | + |
| 234 | + Now we are ready to enable our RDP. |
| 235 | + |
| 236 | +4. Navigate back to the main page for your RDP. |
| 237 | + |
| 238 | + Select the **Summary** tab. |
| 239 | + |
| 240 | +5. Click on the **Connector / RDP**, e.g., `EDP-SBPA-BPCreated-[SAPCommunityDisplayName]`. |
| 241 | + |
| 242 | + Click **Edit** on the top right, and enable the RDP by toggling the **Enabled** setting. |
| 243 | + |
| 244 | + Click the **Apply** button. |
| 245 | + |
| 246 | + Once we enable the RDP, if we navigate to the `Summary` tab, we should see that all the objects are in an operational state. |
| 247 | + |
| 248 | +  |
| 249 | + |
| 250 | +6. Now, go to the SAP S/4HANA Cloud system and create a Business Partner. |
| 251 | + |
| 252 | + This will trigger a Business Partner event which you will receive in your queue. |
| 253 | + |
| 254 | + Check that the queue configured for the RDP is accumulating messages. |
| 255 | + |
| 256 | +  |
| 257 | + |
| 258 | +### Trigger processes in SAP Build Process Automation |
| 259 | + |
| 260 | +Now that you've created events and sent them to your SAP Build Process Automation tenant, create a project that can be triggered by those events. |
| 261 | + |
| 262 | +To achieve this, you can follow the steps in the [Capture Events in SAP Build Process Automation tutorial](../codejam-events-process-6/codejam-events-process-6.md). |
| 263 | + |
| 264 | +### Summary |
| 265 | + |
| 266 | +This tutorial completed all the configuration required for the REST Delivery Point. |
| 267 | + |
| 268 | +1. Created a REST Delivery Point. |
| 269 | +2. Defined an RDP REST Consumer, where we configured the details of our SAP Build Process Automation tenant. |
| 270 | +3. Bound a queue to our RDP. |
| 271 | +4. Added request headers to the queue binding. |
| 272 | +5. Enabled it all. |
| 273 | + |
| 274 | + |
| 275 | +### Further study |
| 276 | + |
| 277 | +In this tutorial, we have learned how to create a REST Delivery Point (RDP) to forward messages from a queue to a REST consumer. We used OAuth 2.0 authentication to securely deliver events to SAP Build Process Automation. Now we know a mechanism to enable systems that expose REST endpoints to "react" to events produced by an event broker service. |
| 278 | + |
| 279 | +* Managing REST Delivery Points - [link](https://docs.solace.com/Services/Managing-RDPs.htm) |
| 280 | +* REST Consumer Authentication Schemes - [link](https://docs.solace.com/Services/Managing-RDPs.htm#configuring-REST-consumer-authentication-schemes) |
| 281 | +* Integration with Advanced Mesh Service Plan for Service Cloud - [link](https://help.sap.com/docs/SAP_S4HANA_CLOUD/0f69f8fb28ac4bf48d2b57b9637e81fa/9b34c841dfba4f82af0825a2f3196ecf.html?locale=en-US) |
| 282 | + |
| 283 | +>**Things to Ponder** |
| 284 | +> |
| 285 | +> 1. What if you would need to transform or enrich the message before sending it to the REST consumer? How would you do it? |
| 286 | +> 2. Can you think of a system within your company that exposes REST endpoints and could benefit from being part of an event-driven architecture? |
0 commit comments