PubSub subscription `dataAsPayload` flag that sends only the `data/data_base64` value of the data attribute to the application
#3.801 aberto em 22 de out. de 2021
Métricas do repositório
- Stars
- (25.672 estrelas)
- Métricas de merge de PR
- (Métricas PR pendentes)
Description
/area runtime
This feature applies only to the HTTP application protocol. This is not a usability issue with the gRPC API spec.
In some cases, the application may not need the full CloudEvent payload sent to the HTTP application. This is particularly the case with raw events, where receiving the CloudEvent wrapper is unexpected/confusing. This also avoids some performance hit in Base64 encoding/decoding when sending binary data (e.g. Avro/Protobuf). It is important to propagate the telemetry trace IDs through the call flow, but those are added to the header of the request to the app.
Here is what the configuration for raw events could look like:
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: products
spec:
pubsubname: pubsub
topic: inventory
route: products
dataAsPayload: true
Note: dataAsPayload is not defined as a metadata attribute because it could apply per route in the case of PubSub Routing:
apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
name: mysubscriptions
spec:
pubsubname: pubsub
topic: inventory
dataAsPayload: false # (maybe) if specified, acts as the default for the routes
routes:
rules:
- match: "event.type == 'widget'"
path: widgets
dataAsPayload: true # overrides the default
- match: "event.type == 'gadget'"
path: gadgets
default: products
defaultDataAsPayload: true
Site note: In hindsight, default should have been a nested structure:
default:
path: products
dataAsPayload: true
I don't think the CRD can be changed now. 🤷
From an SDK perspective (C# shown) the handler's method signature would look like this for dataAsPayload: false
public IActionResult Widget([FromBody] CloudEvent<Widget> widgetEvent)
Or like this with dataAsPayload: true
public IActionResult Widget([FromBody] Widget widget)
Release Note
RELEASE NOTE: Subscriptions can optionally send only the data of a CloudEvent to the application