The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in IETF BCP14 (RFC2119 & RFC8174)
Copyright (c) 2023 General Motors GTO LLC Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. SPDX-FileType: DOCUMENTATION SPDX-FileCopyrightText: 2023 General Motors GTO LLC SPDX-License-Identifier: Apache-2.0
CloudEvents is a CNCF specification for describing events in a common way. We will use CloudEvents to formulate all kinds of uProtocol messages that will be sent to and from uEs.
CloudEvents are:
-
An envelope for information about the occurrence of change in a system, it has a "from" address (source) with the "to" address is optional (sink)
-
carry facts in metadata with standard attributes
-
Self-contained & unique (you don’t need to attach data to an event)
-
Can be encoded/decoded into different formats without losing/modifying information
Cloud Events answers the following in the metadata:
-
What kind of event?-→ type
-
When was it sent? -→ time
-
Who sent it? -→source
-
What is the event unique identifier? -→ id
-
What is the shape of the data event? -→ dataschema
-
What is the event data? -→ data
The specification is transport agnostic (can run over HTTP, MQTT, AMQP, NATS, Kafka), and comes with SDK in most common languages.
CloudEvents can be represented as objects (in the programming language of choice) as well as serialized to any binary or text encoding formats such as protobuf, JSON, AVRO, XML, etc…. CloudEvent are often referred to as "the envelope for data" as it holds the data and metadata.
CloudEvents has defined a set of specifications for the well know formats (ex. JSON, Protobuf, etc..) as well as how to send these messages over well-known transports (ex. HTTP, MQTT, etc..).
Note
|
Additional formats and transports not covered by CloudEvents.io shall be covered in uP-L1 Specifications |
The following section we shall elaborate how map uProtocol Header Attributes (uAttributes) to CloudEvents attributes.
Common attributes apply to all message types.
CE Attribute | uProtocol Attribute | CE Type | RFC2119 | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
N/A |
String |
R |
CloudEvent specification version. This is NOT the uProtocol version
|
|||||||||
|
String |
R |
Unique identifier for the CE
|
|||||||||
N/A |
R |
The Source (address) of the message per table below source Description
|
||||||||||
|
String |
R |
uProtocol CE type
|
|||||||||
R|O |
URI pointing to the method to be invoked
|
|||||||||||
UPayloadFormat (not part of UAttributes) |
String |
O |
Content type of data value. This attribute enables data to carry any type of content, whereby format and encoding might differ from that of the chosen event format
|
|||||||||
|
N/A. (Transport specific) |
Binary |
O |
HMAC generated on the data portion of the message using a device key |
||||||||
|
|
String |
O |
uProtocol Prioritization classifications per QoS. When this field is missing,
|
||||||||
|
|
Uint32 |
R|O |
How long this event should live for after it was generated (in milliseconds). Event expires when: \(t_current > t_{ce_id} + ce_ttl\) When the message type is
otherwise:
|
||||||||
|
|
String |
O |
Contains a version, trace ID, span ID, and trace options as defined in section 3.2. Intended to be compatible with CloudEvents distributed tracing extension. |
Additional attributes are included for RPC for correlation, access control, and more.
Note
|
RPC response RESOURCE portion of a topic is: rpc.response
|
CE Attribute | uProtocol Attribute | CE Type | RFC2119 | Description |
---|---|---|---|---|
|
|
String |
R|O |
Access token per Token-Based uE Access Permissions (TAPs) |
|
|
Integer |
R|O |
Source (senders) uE permission level as defined in Code-Based uE Access Permissions (CAPs) |
CE Attribute | uProtocol Attribute | CE Type | RFC 2119 | Description | Requirements |
---|---|---|---|---|---|
|
|
String |
R |
Request Identifier a.k.a correlation ID between this response and the original request |
|
|
|
Integer |
O |
Communication error attribute populated by uP-L2 dispatchers only when an error has occurred in the delivery of RPC request or response events. |
|
Data portion of the CE contains the application layer (uP-L2) message also known as the UPayload.
In this section we will explain the format (encoding) for CloudEvent message and the impacts on the payload formats.
CE Format | Encoding | Data Format Considerations |
---|---|---|
Binary |
If UPayload is a protobuf message:
If the UPayload is binary and _NOT a protobuf message:
|
|
Text |
If UPayload is a protobuf message:
If UPayload is binary and _NOT a protobuf message:
|
The following are additional recommendations when implementing the protocol:
-
Data and CE SHOULD only be serialized once when it is to be transported over UTransport Interface
The following examples are using the JSON CE format
{
"specversion": "1.0",
"id": "cf8b1bcd-30bd-43be-a8d3-ad1cde652e10",
"source": "//VCU.VIN/body.access/1/door.front_left#Door",
"type": "pub.v1",
"priority": "CS1",
"ttl": 10000,
"data": /* Protobuf serialized Door Message*/
}
{
"specversion": "1.0",
"id": "cf8b1bcd-30bd-43be-a8d3-ad1cde652e10",
"source": "//VCU.VIN/MyAppp/1/rpc.response",
"sink": "//VCU.VIN/body.access/1/rpc.UpdateDoor",
"type": "req.v1",
"priority": "CS4",
"ttl": 50000,
"data": /* Protobuf serialized UpdateDoorRequest Message*/
}
{
"specversion": "1.0",
"id": "5b9fe861-8c1c-4899-9b07-ad1cde652e10",
"source": "//VCU.VIN/body.access/1/rpc.UpdateDoor",
"sink": "//VCU.VIN/MyAppp/1/rpc.response",
"type": "res.v1",
"priority": "CS4",
"reqid": "cf8b1bcd-30bd-43be-a8d3-ad1cde652e10",
"ttl": 50000,
"data": /* Protobuf serialized google.rpc.Status Message*/
}