Merge branch 'v1.10' into UpdateReleaseTo1.10.7

This commit is contained in:
Hannah Hunter 2023-05-17 18:17:58 -04:00 committed by GitHub
commit cea63afa10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 18 deletions

View File

@ -11,39 +11,43 @@ To enable message routing and provide additional context with each message, Dapr
Dapr uses CloudEvents to provide additional context to the event payload, enabling features like: Dapr uses CloudEvents to provide additional context to the event payload, enabling features like:
- Tracing - Tracing
- Deduplication by message Id
- Content-type for proper deserialization of event data - Content-type for proper deserialization of event data
- Verification of sender application
## CloudEvents example ## CloudEvents example
Dapr implements the following CloudEvents fields when creating a message topic. A publish operation to Dapr results in a cloud event envelope containing the following fields:
- `id` - `id`
- `source` - `source`
- `specversion` - `specversion`
- `type` - `type`
- `traceparent` - `traceparent`
- `traceid`
- `tracestate`
- `topic`
- `pubsubname`
- `time` - `time`
- `datacontenttype` (optional) - `datacontenttype` (optional)
The following example demonstrates an `orders` topic message sent by Dapr that includes a W3C `traceid` unique to the message, the `data` and the fields for the CloudEvent where the data content is serialized as JSON. The following example demonstrates a cloud event generated by Dapr for a publish operation to the `orders` topic that includes a W3C `traceid` unique to the message, the `data` and the fields for the CloudEvent where the data content is serialized as JSON.
```json ```json
{ {
"topic": "orders", "topic": "orders",
"pubsubname": "order_pub_sub", "pubsubname": "order_pub_sub",
"traceid": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01", "traceid": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01",
"tracestate": "", "tracestate": "",
"data": { "data": {
"orderId": 1 "orderId": 1
}, },
"id": "5929aaac-a5e2-4ca1-859c-edfe73f11565", "id": "5929aaac-a5e2-4ca1-859c-edfe73f11565",
"specversion": "1.0", "specversion": "1.0",
"datacontenttype": "application/json; charset=utf-8", "datacontenttype": "application/json; charset=utf-8",
"source": "checkout", "source": "checkout",
"type": "com.dapr.event.sent", "type": "com.dapr.event.sent",
"time": "2020-09-23T06:23:21Z", "time": "2020-09-23T06:23:21Z",
"traceparent": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01" "traceparent": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01"
} }
``` ```
@ -65,6 +69,19 @@ As another example of a v1.0 CloudEvent, the following shows data as XML content
## Publish your own CloudEvent ## Publish your own CloudEvent
If you want to use your own CloudEvent, make sure to specify the [`datacontenttype`]({{< ref "pubsub-overview.md#setting-message-content-types" >}}) as `application/cloudevents+json`. If you want to use your own CloudEvent, make sure to specify the [`datacontenttype`]({{< ref "pubsub-overview.md#setting-message-content-types" >}}) as `application/cloudevents+json`.
If the CloudEvent that was authored by the app does not contain the [minimum required fields](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md#required-attributes) in the CloudEvent specification, the message is rejected. Dapr adds the following fields to the CloudEvent if they are missing:
- `time`
- `traceid`
- `traceparent`
- `tracestate`
- `topic`
- `pubsubname`
- `source`
- `type`
- `specversion`
You can add additional fields to a custom CloudEvent that are not part of the official CloudEvent specification. Dapr will pass these fields as-is.
### Example ### Example
@ -102,6 +119,10 @@ Invoke-RestMethod -Method Post -ContentType 'application/cloudevents+json' -Body
{{< /tabs >}} {{< /tabs >}}
## Event deduplication
When using cloud events created by Dapr, the envelope contains an `id` field which can be used by the app to perform message deduplication. Dapr does not handle deduplication automatically. Dapr supports using message brokers that natively enable message deduplication.
## Next steps ## Next steps
- Learn why you might [not want to use CloudEvents]({{< ref pubsub-raw.md >}}) - Learn why you might [not want to use CloudEvents]({{< ref pubsub-raw.md >}})

View File

@ -180,12 +180,12 @@ The `order-processor` service writes, reads, and deletes an `orderId` key/value
const client = new DaprClient() const client = new DaprClient()
// Save state into a state store // Save state into a state store
await client.state.save(DAPR_STATE_STORE_NAME, state) await client.state.save(DAPR_STATE_STORE_NAME, order)
console.log("Saving Order: ", order) console.log("Saving Order: ", order)
// Get state from a state store // Get state from a state store
const savedOrder = await client.state.get(DAPR_STATE_STORE_NAME, order.orderId) const savedOrder = await client.state.get(DAPR_STATE_STORE_NAME, order.orderId)
console.log("Getting Order: ", savedOrd) console.log("Getting Order: ", savedOrder)
// Delete state from the state store // Delete state from the state store
await client.state.delete(DAPR_STATE_STORE_NAME, order.orderId) await client.state.delete(DAPR_STATE_STORE_NAME, order.orderId)