Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

March Developer Challenge - CloudEvents: Week 1

ajmaradiaga
Developer Advocate
Developer Advocate
In this month's developer challenge, we will focus on CloudEvents. We will learn what the CloudEvents specification is, how it has been adopted within SAP and even create our first CloudEvent. We will also create CloudEvents programmatically and send them to one of the different offerings that SAP has to support Event-Driven architectures. Lots to learn, so let's get started.
 
CloudEvents-Developer-Challenge.drawio.png

Links to March's developer challenge:

What is CloudEvents?

CloudEvents-logo.png

Today's system landscapes are very complex and we need to deal with many systems communicating with each other, ideally as close to real-time as possible. Nowadays, a system can publish events to notify other systems of the changes happening within the objects of their system. Given that we are talking of many systems, ideally, there will be a common way of describing the data produced by these systems. The CloudEvents specification can help us with this. We can leverage it to provide a consistent way for how our systems can communicate with others about these events.

As mentioned on the CloudEvents website... CloudEvents is a specification for describing event data in a common way. It's goal is to simplify event declaration and delivery across services, platforms and beyond! The specification is now under the Cloud Native Computing Foundation.

Below is an example of what a CloudEvent message will look like:

 

{
  "specversion": "1.0",
  "type": "com.github.pull_request.opened",
  "source": "https://github.com/cloudevents/spec/pull",
  "subject": "123",
  "id": "A234-1234-1234",
  "time": "2018-04-05T17:31:00Z",
  "comexampleextension1": "value",
  "comexampleothervalue": 5,
  "datacontenttype": "text/xml",
  "data": "<much wow=\"xml\"/>"
}

 

You'll notice that the example above is composed of many attributes, the event context. The context describes the event and is independent of the event data. Meaning that we can somehow process/inspect the event without needing to process its data. Now, let's dive a bit into the message itself.

For more information on the history, development and design rationale behind the specification, see the CloudEvents Primer document.

CloudEvents message format

A CloudEvent message is mainly composed of context attributes and data.

Context Attributes

A number of attributes can be included within the message, these attributes are known as Context Attributes and the idea is that these context attributes can be used to describe the event. We can think of these context attributes as the header information of our event that can be used for filtering and routing. Let's explore some of the attributes available.

NameRequiredDescriptionExample
idIdentifies the event. Producers MUST ensure that source + id is unique for each distinct event.63d6a150-c6a1-4c5b-bcc3-27d90c07941c
sourceIdentifies the context in which an event happened./default/sap.s4.beh/244572008
specversionThe version of the CloudEvents specification which the event uses.1.0
typeDescribes the type of the eventsap.s4.beh.businesspartner.v1.BusinessPartner.Changed.v1
datacontenttype Content type of the value in data.application/json

Extension Context Attributes

A CloudEvent message may also include additional context attributes, which are not defined as part of the specification. These additional attributes are known as "extension attributes" and can be used by the producer systems or intermediaries to include additional metadata to an event, similar to how we can use HTTP custom headers.

For example, in the SAP Digital Vehicle Hub Business Events package, we can see that the event raised when a vehicle changes - sap.dmo.dvh.Vehicle.Changed.v1, contains the extension context attribute sappassport, which is an SAP specific tracing identifier.

 

{
  "specversion": "1.0",
  "type": "sap.dmo.dvh.Vehicle.Changed.v1",
  "source": "/eu10/sap.dmo.dvh",
  "subject": "808E6E30B65149978A443429B29FB300",
  "id": "a823e884-5edc-4194-a81a-f3a3632417ee",
  "time": "2018-04-08 08:31:00",
  "datacontenttype": "application/json",
  "sappassport": "string",
  ....
}

 

 

Data

A CloudEvent message may include a payload but this is not required. If included it will be in the format specified in the datacontenttype context attribute. Although it is not required, we will generally have a payload in messages. Below we can see an example of an event message that contains a payload. In this case, a Business Partner changed event generated by an SAP S/4HANA Cloud Public Edition.

 

 

{
    "type": "sap.s4.beh.businesspartner.v1.BusinessPartner.Changed.v1",
    "specversion": "1.0",
    "source": "/default/sap.s4.beh/244572008",
    "id": "63d6a150-c6a1-4c5b-bcc3-27d90c07941c",
    "time": "2024-02-26T10:53:06Z",
    "datacontenttype": "application/json",
    "data": {
        "BusinessPartner": "1000667"
    }
}

 

 

Check out the Business Partner changed event in the SAP Business Accelerator Hub - https://hub.sap.com/event/CE_BUSINESSPARTNEREVENTS/resource.

SAP's adoption of CloudEvents

SAP is an active contributor to the CloudEvents specification and one of its many adopters. Evidence of that is the different products (event packages) that we can find documented in the SAP Business Accelerator Hub > Events category.

The products listed below document their events in the form of event packages in the SAP Business Accelerator Hub. All their events follow the CloudEvents specification:

  • SAP Agricultural Origination Portal
  • SAP Batch Release Hub for Life Sciences
  • SAP Cell and Gene Therapy Orchestration
  • SAP Cloud for Utilities Foundation
  • SAP Digital Vehicle Hub
  • SAP GRC Cloud - Issue Management and Remediation Service
  • SAP Industry Process Framework
  • SAP Intelligent Clinical Supply Management for Operations
  • SAP Intelligent Clinical Supply Management for Planning
  • SAP Landscape Management Cloud
  • SAP Marketing Cloud
  • SAP Order Management Foundation
  • SAP S/4HANA
  • SAP S/4HANA Cloud Public Edition
  • SAP S/4HANA Utilities for Customer Engagement
  • SAP S/4HANA for Procurement Planning Cloud
  • SAP Subscription Billing

SAP's flagship ERP products, SAP S/4HANA Cloud Public edition and SAP S/4HANA, expose more than 600+ events combined. As you might have noticed from the events that we use as examples above, these events follow the CloudEvents specification. Below we can see the BusinessPartner Created event generated by an SAP S/4HANA Cloud Public Edition and we can see how it follows the CloudEvents specification.

 

 

{
    "type": "sap.s4.beh.businesspartner.v1.BusinessPartner.Created.v1",
    "specversion": "1.0",
    "source": "/default/sap.s4.beh/244572008",
    "id": "194780e0-b5db-1ede-b58a-4550178dff9e",
    "time": "2024-02-26T09:50:00Z",
    "datacontenttype": "application/json",
    "data": {
        "BusinessPartner": "1000667"
    }
}

 

 

📢 Check out this blog post, https://community.sap.com/t5/application-development-blog-posts/cloudevents-at-sap/ba-p/13620137, if you want to learn more about CloudEvents at SAP 🌁.

Week 1 challenge - Create a CloudEvent

👉 Your task for this week is: Create a CloudEvent message and share it as a comment in the comments section below. Note: The CloudEvent message that you submit in the comments section needs to be valid, as it will be checked against a JSON schema.

Let's proceed to create our first CloudEvent message. For this, let's use as an example an existing system in your organisation. You can use as a reference a system that you are familiar with. For example, a system that you know that it interacts/notifies other systems in your landscape about a particular change occurring within it.

The event that we create doesn't need to be of a real system/scenario. The goal of this exercise is for you to get familiar with the message format and create a sample event message that we can use in the future.

In my case, I will use as a reference a ticket managing system and create a CloudEvent message that will be produced whenever a new ticket is created.

 

 

{
  "specversion": "1.0",
  "type": "com.ajmaradiaga.tms.Ticket.Created.v1",
  "source": "https://tms-prod.ajmaradiaga.com/tickets",
  "subject": "IT00010232",
  "id": "d121e256-2afd-1724-c80b-b5l3645357fa",
  "time": "2024-02-22 14:10:00",
  "datacontenttype": "application/json",
  "data": { 
    "id": "IT00010232",
    "description": "Install ColdTurkey to block distracting websites.",
    "urgency": {
      "id": 1,
      "description": "High"
    }
  }
}

 

 

The above payload is what I would submit as an answer for this week's challenge. Now, go ahead, create a CloudEvent message and share it as a comment in the comments section.

 

46 REPLIES 46

ajmaradiaga
Developer Advocate
Developer Advocate

Example submission for this week. Ideally use a code block to nicely format your CloudEvent message :-).

 

{
  "specversion": "1.0",
  "type": "com.ajmaradiaga.tms.Ticket.Created.v1",
  "source": "https://tms-prod.ajmaradiaga.com/tickets",
  "subject": "IT00010232",
  "id": "d121e256-2afd-1724-c80b-b5l3645357fa",
  "time": "2024-02-22 14:10:00",
  "datacontenttype": "application/json",
  "data": { 
    "id": "IT00010232",
    "description": "Install ColdTurkey to block distracting websites.",
    "urgency": {
      "id": 1,
      "description": "High"
    }
  }
}

 

r00k13d3v
Participant

Here is my submission ✌️

 

{
  "specversion": "1.0",
  "type": "com.example.iot.device.event.v1",
  "source": "https://iot-prod.example.com/devices",
  "subject": "device12345-temperature-alert",
  "id": "e241f360-4b3f-4c9b-a5e4-d35456b27f62",
  "time": "2024-03-06 08:34:00",
  "datacontenttype": "application/json",
  "data": { 
    "device_id": "Device12345",
    "event_type": "temperature-alert",
    "description": "Temperature threshold exceeded.",
    "data": {
      "temperature": 75,
      "threshold": 70,
      "units": "Celsius"
    }
  }
}

 

Dan_Wroblewski
Developer Advocate
Developer Advocate
{
  "id": "3a4fe220-4d46-4321-b32d-e40f9a882b1c",
  "source": "/build/events/launch",
  "specversion": "1.0",
  "type": "com.sap.build.app.Launched.v1",
  "datacontenttype": "application/json",
  "subject": ".gpg",
  "time": "2024-03-06 14:10:00",
  "data": { 
    "name": "My Build App",
    "description": "An app that runs a car wash from anywhere.",
    "tenant": "mycompany-5de8ecni"
  }
}



--------------
See all my blogs and connect with me on Twitter / LinkedIn

fjaviergar07
Explorer

Here you go:

 

  {
    "specversion" : "1.0",
    "type" : "com.exercise1.developerchallenge",
    "source" : "https://s4hana/prod/",
    "id" : "BAGXoM7Yw4S2iYHlcoaPd29t7YlFT",
    "time" : "2023-03-06T10:13:00Z",
    "datacontenttype" : "application/json",
    "data" : {
			"id": "00000000001",
			"calendarweek": "10",
			"month": "March",
			"exercise": {
				"task": "Design Cloud Event"
			}
}
}

 

spassaro
Participant
{
  "type": "sap.s4.beh.purchaserequisition.v1.PurchaseRequisition.Changed.v1",
  "specversion": "1.0",
  "source": "nedgia/eventmeshdev/dev",
  "id": "AA06tkhWHt6FoCOmSZ/6+Q==",
  "time": "2023-06-27T15:40:17Z",
  "datacontenttype": "application/json",
  "data": {
  "PurchaseRequisition": "60004767"
  }
  }

 

What a interesting challenge Antonio! Looking forward to next weeks!!

xavisanse
Active Participant
0 Kudos

 

{
  "specversion": "1.0",
  "type": "com.awesome_company.sales_order.Updated.v1",
  "source": "https://prod.illidian.awesome_company.com/sales_orders",
  "subject": "AWO0190240000132024",
  "id": "f8e9d7c6-5b4a-3c2d-1e0f-9a8b7c6d5e4f",
  "time": "2024-03-06 13:00:00",
  "datacontenttype": "application/json",
  "data": { 
    "salesOrder": "9024000013",
    "company": "AWO01",
    "year": "2024",
    "status": "Shipped"
  }
}

 

0 Kudos

@xavisanse the payload is missing a closing curly brace but that's ok. The essence is there 🙂

 

spirit2681
Explorer

Here is my submission:

{
  "specversion": "1.0",
  "type": "com.sonal.plm.NPDI.Created.v1",
  "source": "https://plm-prod.sonal.com/npdis",
  "subject": "NPDI000000001",
  "id": "196179a2-6cf1-4166-9975-51f9afdb3a0d",
  "time": "2024-03-06 12:00:00",
  "datacontenttype": "application/json",
  "data": { 
    "id": "NPDI000000001",
    "description": "New Product Development and Introduction Created"
  }
}

Vijay_Sankar_
Participant

Here you go:

{
  "type": "sap.s4.beh.product.v1.Product.Changed.v1",
  "specversion": "1.0",
  "source": "/default/sap.s4.beh/test",
  "id": "6145bd0e-9b19-1edd-a18c-2966eaf68c13",
  "time": "2024-03-06T16:35:49Z",
  "datacontenttype": "application/json",
  "data": {
    "Product": "TEST MATERIALS"
  }
}

saitgunacorel
Discoverer

Here you go:

 

{
    "specversion": "1.0",
    "type": "com.example.sales.Order.Updated.v1",
    "source": "https://sales.example.com/orders",
    "subject": "OR10001001",
    "id": "fc04acbf-9112-4b5f-8898-ad01f2a18b34",
    "time": "2024-03-06 15:45:00",
    "datacontenttype": "application/json",
    "data": {
        "id": "OR10001001",
        "changedBy": "TechnicalUser01",
        "dataUrl": "https://sales.example.com/api/orders('OR10001001')"
    }
}

thomas_jung
Developer Advocate
Developer Advocate
{
  "specversion": "1.0",
  "type": "com.example.myapp.resource.created",
  "source": "/myapp/resources/1234567890",
  "id": "A234-1234-1234",
  "time": "2023-03-05T18:00:00Z",
  "datacontenttype": "application/json",
  "data": {
    "resourceId": "1234567890",
    "resourceName": "My Resource",
    "resourceType": "myapp.com/resources"
  }
}

PriyankaChak
Active Contributor
{
    "specversion": "1.0",
    "type": "com.servicechannel.WorkOrder.Created.v1",
    "source": "https://test.servicechannel.com/workorders",
    "id": "cca04a57-9d63-40ee-b39b-89cfc523e19d",
    "time": "2024-03-07T17:31:00Z",
    "datacontenttype": "application/json",
    "data": {
        "purchasenumber": "84409626",
        "status": {
            "primary": "open"
        }
    }
}

amitcruz
Participant
{
"type": "sap.s4.beh.product.v1.Product.Created.v1",
"specversion": "1.0",
"source": "/default/sap.s4.beh/T49CLNT110",
"id": "000d3aa9-b9cf-1eee-81be-b537844fe89c",
"time": "2023-06-08T12:11:57Z",
"datacontenttype": "application/json",
"data": {
"Product": "6000002678"
}
}

Alpesa1990
Explorer
{
"specversion": "1.0",
"id": "62706ed3-3f4c-4a48-a2e7-8f201301822b",
"type": ".com.alpesadevcha.v1",
"source": "/alpesadev/test",
"time": "2024-03-07T08:00:00Z",
"datacontenttype": "application/json",
"data": {
	"employee": "80001000"
	}
}

emiliocampo
Explorer
{
    "type": "sap.s4.beh.maintenanceorder.v1.MaintenanceOrder.SetToTechCompleted.v1",
    "datacontenttype": "application/json",
    "specversion": "1.0",
    "source": "https://my400000.s4hana.cloud.sap/",
    "subject":"OR000004000020",
    "id": "QgEK7wzuHtqdhJwqCS+VOA==",
    "time": "2024-03-07T11:00:00Z",
    "data": {
        "MaintenanceOrder": "4000020",
        "MaintenanceOrderType":"YA01"
    }
}

tobiasz_h
Active Participant

Hello,

{
  "type": "sap.s4.beh.product.v1.Product.Changed.v1",
  "datacontenttype": "application/json",
  "specversion": "1.0",
  "source": "../dictionary",
  "subject": "productId:123",
  "id": "QgEK7wzuHtqdhJwqCS+VOA==",
  "time": "2024-03-05T17:31:00Z",
  "data": {
    "Product": "123",
    "ProductCategory": "TELE",
    "ProductType": "LCD"
  }
}

ceedee666
Active Contributor

Here is my try to create a "Production order created" event.

{
  "type": "sap.s4.beh.productionorder.v1.ProductionOrder.Created.v1",
  "datacontenttype": "application/json",
  "specversion": "1.0",
  "source": "m32z",
  "subject": "Production Order 1000206 created",
  "id": "QgEK7wzuHtqdhJwqCS+VOA==",
  "time": "2024-02-08T12:00:00Z",
  "data": {
    "ProductionOrder": "1000206",
    "ProductionOrderType": "PP01",
    "ProductionPlant": "HD00"
  }
}

TinhLeo
Participant

 

{
  "type": "sap.s4.tinhtd.info.v1.SaleOrder.Created.v1",
  "datacontenttype": "application/json",
  "specversion": "1.0",
  "source": "https://cloudevent.tinhtd.info/saleorders",
  "subject": "Sales Order 10608090 created",
  "id": "aHR0cHM6Ly9jb21tdW5pdHkuc2FwLmNvbS90N",
  "time": "2024-03-08T13:00:00Z",
  "data": {
    "SaleOrder": "10608090",
    "OrderType": "ZASO",
    "OrdetItems": [
      {
        "ProductId":"P001",
        "Price":200,
        "Quantity":1
      }
    ]
  }
}

 

TinhLeo
https://saplife.org

ajos
Explorer

{
"type": "sap.s4.deliveryPGI.Created.v1",
"specversion": "1.0",
"source": "/default/sap.s4.beh/244572008",
"id": "194780e0-b5db-1ede-b58a-4550178dff9e",
"time": "2024-02-26T09:50:00Z",
"datacontenttype": "application/json",
"data": {
"DeliveryNo": "1000667",
"DeliveryType: "ZDRV"
}

ajmaradiaga
Developer Advocate
Developer Advocate
0 Kudos

@ajos, similar to @xavisanse before you are missing to close the payload but the essence is there.

MarcelloUrbani
Active Contributor
0 Kudos
{
  id: v1(),
  specversion: "1.0",
  source: "week1testprog",
  type: "week1testprog.demoevent",
  datacontenttype: "application/json",
  data: {
    salutation: "hello"
  }
}

Ruthiel
Product and Topic Expert
Product and Topic Expert
{
  "type": "sap.s4.beh.allergen.v1.Allergen.Created.v1",
  "specversion": "1.0",
  "source": "../dictionary",
  "subject": "string",
  "id": "QgEK7wzuHtqdhJwqCS+VOA==",
  "time": "2018-04-05T17:31:00Z",
  "datacontenttype": "application/json",
  "data": {
    "AllergenInternalID": "string"
  }
}

MatLakaemper
Participant
0 Kudos

Hi Antonio,

in my trial-Account i can´t find anything about the Event-Mesh.
Also after Activation the IntegrationSuite i can´t find Event-Mesh-Topics. 
On reading the blogposts and discussions i thougt, that the Event-Mesh-Functions
will be available after activating the Integration-Suite.

What am i doing wrong?

kind Regards
Matthias

 

 

0 Kudos

@MatLakaemper, SAP Event Mesh is no longer available in the trial account - https://community.sap.com/t5/technology-blogs-by-sap/sap-event-mesh-trial-to-be-retired/ba-p/1355897.... At the moment SAP Event Mesh is a standalone service in a paid account, not available on trial. Related to SAP Integration Suite, there will be soon an event-capability part of SAP Integration Suite and you can find more information in https://roadmaps.sap.com. That said, SAP Event Mesh is not needed to complete the developer challenge 😉

 

0 Kudos

Hello , Could you please elaborate what will happen to the scenarios that are developed using SAP Event Mesh standalone service ( Not Advanced Event Mesh ) ? When you say "SAP Event Mesh is a standalone service but will be soon a capability of SAP Integration Suite" , does this mean we need to subscribe to SAP Integration Suite to avail SAP Event Mesh Standalone Service ? Also could you please elaborate on difference between Event Mesh Standalone , Advanced Event Mesh and SAP Event Broker for SAP cloud applications ?

0 Kudos

> Event-capability part of SAP Integration Suite
My wording in the response might not be the best. I apologise for that and I've fixed it. You can find some information regarding the event-capability part of SAP Integration Suite at https://roadmaps.sap.com

> Elaborate on the difference between the event offering
You can find more info here: https://community.sap.com/t5/application-development-blog-posts/cloudevents-at-sap/ba-p/13620137

 

pamoli_banerjee
Explorer
{
    "type": "sap.s4.beh.salesorder.v1.SalesOrder.Created.v1",
    "specversion": "1.0",
    "source": "/default/sap.s4.beh/SXXXXXX",
    "id": "a590d392-80be-1ede-a598-d34338408017",
    "time": "2023-12-07T06:05:25Z",
    "datacontenttype": "application/json",
    "data": {
        "SalesOrder": "9999",
        "EventRaisedDateTime": "2023-12-07T06:05:19.578802Z",
        "SalesOrderType": "TA",
        "SalesOrganization": "1710",
        "DistributionChannel": "10",
        "OrganizationDivision": "00",
        "SoldToParty": "17100001"
    }
}

sainithesh21
Active Participant

Here is my week 1 submission.

 

{ "specversion": "1.0", "type": "com.nithesh.app.resource.created", "source": "/app/resources/2124587451", "id": "N214-5234-9856", "time": "2024-03-02T18:00:00Z", "datacontenttype": "application/json", "data": { "resourceId": "M93157232", "resourceName": "Nithesh Resource", "resourceType": "nithesh.com/resources" } }

 

kasch-code
Participant
{
  "type": "sap.s4.beh.purchaseorder.v1.PurchaseOrder.Created.v1",
  "datacontenttype": "application/json",
  "specversion": "1.0",
  "source": "https://s4.cloud/",
  "subject": "OR1234567890",
  "id": "QgEK7wzuHtqdhJwqCS+VOA==",
  "time": "2024-03-11T12:31:05Z",
  "data": {
    "PurchaseOrder": "1234567890"
  }
}

SyambabuAllu
Contributor
{
	"type": "sap.s4.beh.centralrequestforquotation.v1.CentralRequestForQuotation.SuccssrDocCrted.v1",
	"specversion": "1.0",
	"source": "/default/sap.s4.beh/s4hc",
	"id": "QgEK7wzuHtqdeJwqCS+VOA==",
	"time": "2024-03-11T13:00:00Z",
	"datacontenttype": "application/json",
	"data": {
		"CentralRequestForQuotation": "7500000012"
	}
}

MatLakaemper
Participant

Hi, 
after getting access to an Event-Mesh-System in our company,
i have generated the Event-Message via Postman. 
Consuming by Event-Mesh-Test-Area and by webhook.site.

MatLakaemper_0-1710185166009.png

MatLakaemper_1-1710185189434.png

 



 

0 Kudos

@MatLakaemper, there is no code block in the response but I can see that the payload in the screenshot is valid.

{
    "type": "sap-business-One-fake",
    "specversion": "1.0",
    "source": "/default/sap.s4.beh/244572008",
    "id": "63d6a150-c6a1-4c5b-bcc3-27d90c07941c",
    "time": "2024-02-26T10:53:062",
    "datacontenttype": "application/json",
    "data": {
        "BusinessPartner": "Rübennase",
        "Theme": "Life of Brian"
    }
}

 

TiagoAlmeida
Participant
{
  "specversion": "1.0",
  "type": "com.example.iot.power.consumption",
  "source": "https://example.talmeida.com/devices",
  "subject": "power-measurement",
  "id": "bafa9642-563b-4ff5-b697-58d91a77b988",
  "time": "2024-03-10 10:00:00",
  "datacontenttype": "application/json",
  "data": { 
    "id": "power-measurement-bafa9642-563b-4ff5-b697-58d91a77b988",
    "description": "Power measurement",
    "measure": "10",
	"unit": "Wh"
  }
}

My submission. Thanks in advance! 

ajmaradiaga
Developer Advocate
Developer Advocate
0 Kudos

ICYMI... Week 2 challenge is now available! https://community.sap.com/t5/application-development-discussions/march-developer-challenge-cloudeven.... In Week 2, we expand on what we learnt in week 1 and we will create our first CloudEvent programmatically.

dagoca_abapcl
Explorer

Interesting challenge, I hope I'm not too late.


{
"id": "1fc7fc18-0a82-4f92-a18c-877d336b9be0",
"source": "https://cloud.dagoca.com/events/spec/pull",
"specversion": "1.0",
"type": "com.sap.build.app.Launched.v1",
"datacontenttype": "application/json",
"subject": "create users",
"time": "2024-03-06T14:10:00",
"data": {
"users": [
{
"name": "David",
"lastName": "González",
"password": "MTIzNA==",
"country": "CL"
}
]
}
}

0 Kudos

Not at all... the challenge is "active" the entire month of March. Now go ahead and check out the challenge for week 2 🙂