Skip to content

Commit b2812f1

Browse files
committed
Docs cloud events
1 parent 9017ddd commit b2812f1

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,17 @@ A Cloud Event message has the following structure:
874874
}
875875
```
876876
877+
To configure the CloudEvents format, the service needs to be annotated in addition with `@websocket.format: 'cloudevent'` or
878+
`@ws.format: 'cloudevent'`.
879+
880+
```cds
881+
@ws
882+
@ws.format: 'cloudevent'
883+
service CloudEventService {
884+
// ...
885+
}
886+
```
887+
877888
To create a Cloud Event compatible CDS event, either the event is modeled as CDS service event according to the specification
878889
or a CDS event is mapped via annotations to a Cloud Event compatible event.
879890
@@ -1010,6 +1021,54 @@ cloud event data section.
10101021
10111022
Static and dynamic annotations can be combined. Static values have precedence over dynamic values, if defined.
10121023
1024+
##### Cloud Event Operation
1025+
1026+
CDS service operations (actions or functions) can also be exposed via cloud event. The operation name is derived from the `@websocket.cloudevent.name` or
1027+
`@ws.cloudevent.name` annotation. Emitting a cloud event based websocket event that matches the annotation value of `name`, calls the
1028+
respective service operation handler.
1029+
1030+
The operation parameter structure can be either modelled according to the Cloud Event specification using the attributes as parameter names or
1031+
mapped via annotations like `@websocket.cloudevent.<annotation>` or `@ws.cloudevent.<annotation>` to a Cloud Event compatible structure.
1032+
1033+
**Examples:**
1034+
1035+
**Model Operation Parameters:**
1036+
1037+
```cds
1038+
type CloudEventDataType : {
1039+
appinfoA : String;
1040+
appinfoB : Integer;
1041+
appinfoC : Boolean;
1042+
};
1043+
1044+
@ws.cloudevent.name: 'com.example.someevent'
1045+
action sendCloudEventModel( subject : String, comexampleextension1 : String, comexampleothervalue : Integer, data: CloudEventDataType) returns Boolean;
1046+
```
1047+
1048+
**Map Operation Parameters:**
1049+
1050+
```cds
1051+
@ws.cloudevent.name: 'com.example.someevent'
1052+
@ws.cloudevent.subject: 'cloud'
1053+
action sendCloudEventMap(
1054+
@ws.cloudevent.subject subject : String,
1055+
@ws.cloudevent.comexampleextension1 extension1 : String,
1056+
@ws.cloudevent.comexampleothervalue othervalue : Integer,
1057+
appinfoA : String,
1058+
appinfoB : Integer,
1059+
appinfoC : Boolean
1060+
@ws.ignore appinfoD : String
1061+
) returns Boolean;
1062+
```
1063+
1064+
Unmapped operation parameters are consumed as cloud event data section and can be skipped for cloud event data section
1065+
via `@ws.ignore`, if not necessary.
1066+
1067+
##### Cloud Event Format Alternative
1068+
1069+
Alternatives for format `cloudevent` also allows to use the plural name `@websocket.format: 'cloudevents'` or `@ws.format: 'cloudevents'`,
1070+
if preferred. All headers and annotations are also named in plural form accordingly, e.g. `@ws.cloudevents.name`, etc.
1071+
10131072
#### Custom Format
10141073
10151074
A custom websocket format implementation can be provided via a path relative to the project root

src/format/cloudevents.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
3+
const CloudEventFormat = require("./cloudevent");
4+
const cds = require("@sap/cds");
5+
6+
class CloudEventsFormat extends CloudEventFormat {
7+
constructor(service, origin) {
8+
super(service, origin);
9+
this.name = "cloudevents";
10+
this.identifier = "type";
11+
this.LOG = cds.log(`/websocket/${this.name}`);
12+
}
13+
}
14+
15+
module.exports = CloudEventsFormat;

src/format/generic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class GenericFormat extends BaseFormat {
99
super(service, origin);
1010
this.name = name;
1111
this.identifier = identifier || "name";
12-
this.LOG = cds.log(`/websocket/${name}`);
12+
this.LOG = cds.log(`/websocket/${this.name}`);
1313
}
1414

1515
parse(data) {

0 commit comments

Comments
 (0)