From cda992a511f774b91f0d748ea05b4d44ad5a5d4b Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Wed, 14 Jun 2023 11:58:49 -0400 Subject: [PATCH 01/11] add override section; still working on example Signed-off-by: Hannah Hunter --- .../pubsub/pubsub-cloudevents.md | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md index 251d3f234c1..36ea388e11f 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md @@ -66,6 +66,45 @@ As another example of a v1.0 CloudEvent, the following shows data as XML content } ``` +### Override CloudEvent values + +You can override CloudEvent values by replacing some metadata with the following: +- `cloudevent-id`: overrides `id` +- `cloudevent-source`: overrides `source` +- `cloudevent-type`: overrides `type` +- `cloudevent-traceid`: overrides `traceid` +- `cloudevent-tracestate`: overrides `tracestate` +- `cloudevent-traceparent`: overrides `traceparent` + +{{% alert title="Note" color="primary" %}} +The following metadata can't be overridden: +- `data` +- `topic` +- `pubsub` +- `datacontenttype` +{{% /alert %}} + +For example, to override the values from [the CloudEvent example]({{< ref "#cloudevents-example" >}}) above: + +```json +{ + "topic": "orders", + "pubsubname": "order_pub_sub", + "traceid": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01", + "tracestate": "", + "data": { + "orderId": 1 + }, + "id": "5929aaac-a5e2-4ca1-859c-edfe73f11565", + "specversion": "1.0", + "datacontenttype": "application/json; charset=utf-8", + "source": "checkout", + "type": "com.dapr.event.sent", + "time": "2020-09-23T06:23:21Z", + "traceparent": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01" +} +``` + ## 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`. From 79ff44e3236715f946a210e2684816f75ac73dc9 Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Wed, 14 Jun 2023 12:05:44 -0400 Subject: [PATCH 02/11] start example Signed-off-by: Hannah Hunter --- .../building-blocks/pubsub/pubsub-cloudevents.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md index 36ea388e11f..2cafe5c6e8f 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md @@ -84,24 +84,24 @@ The following metadata can't be overridden: - `datacontenttype` {{% /alert %}} -For example, to override the values from [the CloudEvent example]({{< ref "#cloudevents-example" >}}) above: +For example, to override the applicable values from [the first CloudEvent example above]({{< ref "#cloudevents-example" >}}): ```json { "topic": "orders", "pubsubname": "order_pub_sub", - "traceid": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01", - "tracestate": "", + "cloudevent-traceid": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01", + "cloudevent-tracestate": "", "data": { "orderId": 1 }, - "id": "5929aaac-a5e2-4ca1-859c-edfe73f11565", + "cloudevent-id": "5929aaac-a5e2-4ca1-859c-edfe73f11565", "specversion": "1.0", "datacontenttype": "application/json; charset=utf-8", - "source": "checkout", - "type": "com.dapr.event.sent", + "cloudevent-source": "checkout", + "cloudevent-type": "com.dapr.event.sent", "time": "2020-09-23T06:23:21Z", - "traceparent": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01" + "cloudevent-traceparent": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01" } ``` From 50180c4fd01ba64980d665701c9bff9ae835362d Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Wed, 21 Jun 2023 11:39:23 -0400 Subject: [PATCH 03/11] updates from bernd Signed-off-by: Hannah Hunter --- .../pubsub/pubsub-cloudevents.md | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md index 2cafe5c6e8f..ad55db3320f 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md @@ -68,7 +68,8 @@ As another example of a v1.0 CloudEvent, the following shows data as XML content ### Override CloudEvent values -You can override CloudEvent values by replacing some metadata with the following: +When not provided, Dapr automatically generates several CloudEvent properties. You can override these generated CloudEvent properties by providing the following optional metadata keys: + - `cloudevent-id`: overrides `id` - `cloudevent-source`: overrides `source` - `cloudevent-type`: overrides `type` @@ -76,12 +77,8 @@ You can override CloudEvent values by replacing some metadata with the following - `cloudevent-tracestate`: overrides `tracestate` - `cloudevent-traceparent`: overrides `traceparent` -{{% alert title="Note" color="primary" %}} -The following metadata can't be overridden: -- `data` -- `topic` -- `pubsub` -- `datacontenttype` +{{% alert title="Important" color="warning" %}} +While you can override `traceid` and `tracestate`, this is not the recommended way to specify trace ID or trace state. {{% /alert %}} For example, to override the applicable values from [the first CloudEvent example above]({{< ref "#cloudevents-example" >}}): @@ -90,12 +87,6 @@ For example, to override the applicable values from [the first CloudEvent exampl { "topic": "orders", "pubsubname": "order_pub_sub", - "cloudevent-traceid": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01", - "cloudevent-tracestate": "", - "data": { - "orderId": 1 - }, - "cloudevent-id": "5929aaac-a5e2-4ca1-859c-edfe73f11565", "specversion": "1.0", "datacontenttype": "application/json; charset=utf-8", "cloudevent-source": "checkout", @@ -105,6 +96,28 @@ For example, to override the applicable values from [the first CloudEvent exampl } ``` +`cloudevent-id` should be specified in the publish metadata request, not the payload. For example: + +{{< tabs Python >}} + +{{% codetab %}} + + +```python +resp = d.publish_event( + pubsub_name='pubsub', + topic_name='TOPIC_A', + data=json.dumps(req_data), + publish_metadata={'cloudevent-id': '5929aaac-a5e2-4ca1-859c-edfe73f11565'} +) +``` + +{{% /codetab %}} + +{{< /tabs >}} + + + ## 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`. From 4246f03e978628dd6cb6e5d1a293479ef43b7729 Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Wed, 21 Jun 2023 16:42:22 -0400 Subject: [PATCH 04/11] remove python example per bernd Signed-off-by: Hannah Hunter --- .../building-blocks/pubsub/pubsub-cloudevents.md | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md index ad55db3320f..1aac61ec676 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md @@ -96,21 +96,7 @@ For example, to override the applicable values from [the first CloudEvent exampl } ``` -`cloudevent-id` should be specified in the publish metadata request, not the payload. For example: - -{{< tabs Python >}} - -{{% codetab %}} - - -```python -resp = d.publish_event( - pubsub_name='pubsub', - topic_name='TOPIC_A', - data=json.dumps(req_data), - publish_metadata={'cloudevent-id': '5929aaac-a5e2-4ca1-859c-edfe73f11565'} -) -``` +`cloudevent-id` should be specified in the publish metadata request, not the payload. {{% /codetab %}} From e49f6066f02c114b54d116bf267ef6769fc6781c Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Wed, 21 Jun 2023 16:58:10 -0400 Subject: [PATCH 05/11] forgot to remove shortcode Signed-off-by: Hannah Hunter --- .../building-blocks/pubsub/pubsub-cloudevents.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md index 1aac61ec676..fda0e5f95a2 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md @@ -98,11 +98,6 @@ For example, to override the applicable values from [the first CloudEvent exampl `cloudevent-id` should be specified in the publish metadata request, not the payload. -{{% /codetab %}} - -{{< /tabs >}} - - ## Publish your own CloudEvent From e24313c2f14ee2e410be92367121446817037c42 Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Thu, 22 Jun 2023 12:01:29 -0400 Subject: [PATCH 06/11] tweak Signed-off-by: Hannah Hunter --- .../building-blocks/pubsub/pubsub-cloudevents.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md index efffd59991c..dcad07cb974 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md @@ -77,9 +77,7 @@ When not provided, Dapr automatically generates several CloudEvent properties. Y - `cloudevent-tracestate`: overrides `tracestate` - `cloudevent-traceparent`: overrides `traceparent` -{{% alert title="Important" color="warning" %}} -While you can override `traceid` and `tracestate`, this is not the recommended way to specify trace ID or trace state. -{{% /alert %}} +The CloudEvent override metadata properties apply globally for all pub/sub components. For example, to override the applicable values from [the first CloudEvent example above]({{< ref "#cloudevents-example" >}}): @@ -96,7 +94,13 @@ For example, to override the applicable values from [the first CloudEvent exampl } ``` -`cloudevent-id` should be specified in the publish metadata request, not the payload. +{{% alert title="Important" color="warning" %}} +While you can override `traceid` and `tracestate`, this is not the recommended way to specify trace ID or trace state. The following fields should be specified in the publish metadata request, not the JSON payload: +- `cloudevent-id` +- `cloudevent-traceid` +- `cloudevent-tracestate` + +{{% /alert %}} ## Publish your own CloudEvent From fed1396c760da7e052289f0436a2eba6bf39417c Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Wed, 28 Jun 2023 18:05:55 -0400 Subject: [PATCH 07/11] update alert Signed-off-by: Hannah Hunter --- .../building-blocks/pubsub/pubsub-cloudevents.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md index dcad07cb974..3764f2c8616 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md @@ -66,6 +66,12 @@ As another example of a v1.0 CloudEvent, the following shows data as XML content } ``` +{{% alert title="Important" color="warning" %}} +While you can specify `traceid`/`traceparent` and `tracestate` in the metadata request, it's recommended to use Open Telementry and Zipkin protocols for distributed traces. [Learn more about distributed tracing.]({{< ref "tracing-overview.md" >}}) + +{{% /alert %}} + + ### Override CloudEvent values When not provided, Dapr automatically generates several CloudEvent properties. You can override these generated CloudEvent properties by providing the following optional metadata keys: @@ -90,15 +96,11 @@ For example, to override the applicable values from [the first CloudEvent exampl "cloudevent-source": "checkout", "cloudevent-type": "com.dapr.event.sent", "time": "2020-09-23T06:23:21Z", - "cloudevent-traceparent": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01" } ``` {{% alert title="Important" color="warning" %}} -While you can override `traceid` and `tracestate`, this is not the recommended way to specify trace ID or trace state. The following fields should be specified in the publish metadata request, not the JSON payload: -- `cloudevent-id` -- `cloudevent-traceid` -- `cloudevent-tracestate` +While you can specify and then override `traceid`/`traceparent` and `tracestate`, doing this may interfere with tracing tools. It's recommended to use Open Telementry and Zipkin protocols for distributed traces. [Learn more about distributed tracing.]({{< ref tracing-overview.md >}}) {{% /alert %}} From 0804779f0102b1ed09b1be49bd2120228de2c1e2 Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Thu, 29 Jun 2023 12:36:56 -0400 Subject: [PATCH 08/11] update per mark Signed-off-by: Hannah Hunter --- .../pubsub/pubsub-cloudevents.md | 90 +++++++++++++++---- 1 file changed, 75 insertions(+), 15 deletions(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md index 3764f2c8616..b1495863444 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md @@ -14,9 +14,15 @@ Dapr uses CloudEvents to provide additional context to the event payload, enabli - Content-type for proper deserialization of event data - Verification of sender application -## CloudEvents example +You can choose any of the three methods for publish a CloudEvent via pub/sub: -A publish operation to Dapr results in a cloud event envelope containing the following fields: +1. Write a pub/sub event, which is then automatically wrapped by Dapr in a CloudEvent envelope. +1. Retain the CloudEvents attributes automatically provided by Dapr while overriding any of the standard CloudEvent properties. +1. Supply your own full CloudEvent envelope. + +## Dapr-generated CloudEvents example + +Writing a publish operation to Dapr automatically wraps it in a CloudEvent envelope containing the following fields: - `id` - `source` @@ -30,7 +36,9 @@ A publish operation to Dapr results in a cloud event envelope containing the fol - `time` - `datacontenttype` (optional) -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. +The following example demonstrates a CloudEvent 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 { @@ -66,15 +74,9 @@ As another example of a v1.0 CloudEvent, the following shows data as XML content } ``` -{{% alert title="Important" color="warning" %}} -While you can specify `traceid`/`traceparent` and `tracestate` in the metadata request, it's recommended to use Open Telementry and Zipkin protocols for distributed traces. [Learn more about distributed tracing.]({{< ref "tracing-overview.md" >}}) - -{{% /alert %}} - - -### Override CloudEvent values +## Override Dapr-generated CloudEvents values -When not provided, Dapr automatically generates several CloudEvent properties. You can override these generated CloudEvent properties by providing the following optional metadata keys: +Dapr automatically generates several CloudEvent properties. You can override these generated CloudEvent properties by providing the following optional metadata keys: - `cloudevent-id`: overrides `id` - `cloudevent-source`: overrides `source` @@ -85,22 +87,79 @@ When not provided, Dapr automatically generates several CloudEvent properties. Y The CloudEvent override metadata properties apply globally for all pub/sub components. -For example, to override the applicable values from [the first CloudEvent example above]({{< ref "#cloudevents-example" >}}): +### Example + +To override the `source` and `id` values from [the CloudEvent example above]({{< ref "#cloudevents-example" >}}) in code: + +{{< tabs "Python" ".NET" >}} + +{{% codetab %}} + +```python +with DaprClient() as client: + for i in range(1, 10): + order = {'orderId': i} + # Publish an event/message using Dapr PubSub + result = client.publish_event( + pubsub_name='order_pub_sub', + topic_name='orders', + publish_metadata={'cloudevent-id: 'd99b228f-6c73-4e78-8c4d-3f80a043d317', cloudevent-source: 'payment'} + ) +``` + +{{% /codetab %}} + + +{{% codetab %}} + +```csharp +for (int i = 1; i <= 10; i++) { + var order = new Order(i); + using var client = new DaprClientBuilder().Build(); + + // Override cloudevent metadata + var metadata = new Dictionary() { + { "cloudevent.source", "payment" }, + { "cloudevent.id", "d99b228f-6c73-4e78-8c4d-3f80a043d317" } + } + + // Publish an event/message using Dapr PubSub + await client.PublishEventAsync("order_pub_sub", "orders", order, metadata); + Console.WriteLine("Published data: " + order); + + await Task.Delay(TimeSpan.FromSeconds(1)); +} +``` + +{{% /codetab %}} + +{{< /tabs >}} + + +The JSON payload then reflects the new `source` and `id` values: + ```json { "topic": "orders", "pubsubname": "order_pub_sub", + "traceid": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01", + "tracestate": "", + "data": { + "orderId": 1 + }, + "id": "d99b228f-6c73-4e78-8c4d-3f80a043d317", "specversion": "1.0", "datacontenttype": "application/json; charset=utf-8", - "cloudevent-source": "checkout", - "cloudevent-type": "com.dapr.event.sent", + "source": "payment", + "type": "com.dapr.event.sent", "time": "2020-09-23T06:23:21Z", + "traceparent": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01" } ``` {{% alert title="Important" color="warning" %}} -While you can specify and then override `traceid`/`traceparent` and `tracestate`, doing this may interfere with tracing tools. It's recommended to use Open Telementry and Zipkin protocols for distributed traces. [Learn more about distributed tracing.]({{< ref tracing-overview.md >}}) +While you can override `traceid`/`traceparent` and `tracestate`, doing this may interfere with tracing tools. It's recommended to use Open Telementry and Zipkin protocols for distributed traces. [Learn more about distributed tracing.]({{< ref tracing-overview.md >}}) {{% /alert %}} @@ -108,6 +167,7 @@ While you can specify and then override `traceid`/`traceparent` and `tracestate` ## 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 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` From 01f78695aa7acfcff85209ab62e4b870b19d8810 Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Thu, 29 Jun 2023 14:06:39 -0400 Subject: [PATCH 09/11] typo Signed-off-by: Hannah Hunter --- .../building-blocks/pubsub/pubsub-cloudevents.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md index b1495863444..3407cb6251a 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md @@ -14,7 +14,7 @@ Dapr uses CloudEvents to provide additional context to the event payload, enabli - Content-type for proper deserialization of event data - Verification of sender application -You can choose any of the three methods for publish a CloudEvent via pub/sub: +You can choose any of three methods for publish a CloudEvent via pub/sub: 1. Write a pub/sub event, which is then automatically wrapped by Dapr in a CloudEvent envelope. 1. Retain the CloudEvents attributes automatically provided by Dapr while overriding any of the standard CloudEvent properties. From fac5e6a2c69ed4b9b8fd67fe7a298c077121fa89 Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Fri, 30 Jun 2023 09:31:18 -0400 Subject: [PATCH 10/11] mark review Signed-off-by: Hannah Hunter --- .../pubsub/pubsub-cloudevents.md | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md index 3407cb6251a..4c987bb3936 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md @@ -16,13 +16,13 @@ Dapr uses CloudEvents to provide additional context to the event payload, enabli You can choose any of three methods for publish a CloudEvent via pub/sub: -1. Write a pub/sub event, which is then automatically wrapped by Dapr in a CloudEvent envelope. -1. Retain the CloudEvents attributes automatically provided by Dapr while overriding any of the standard CloudEvent properties. -1. Supply your own full CloudEvent envelope. +1. Send a pub/sub event, which is then wrapped by Dapr in a CloudEvent envelope. +1. Replace specific CloudEvents attributes provided by Dapr by overriding the standard CloudEvent properties. +1. Write your own CloudEvent envelope as part of the pub/sub event. ## Dapr-generated CloudEvents example -Writing a publish operation to Dapr automatically wraps it in a CloudEvent envelope containing the following fields: +Sending a publish operation to Dapr automatically wraps it in a CloudEvent envelope containing the following fields: - `id` - `source` @@ -63,20 +63,24 @@ As another example of a v1.0 CloudEvent, the following shows data as XML content ```json { - "specversion" : "1.0", - "type" : "xml.message", - "source" : "https://example.com/message", - "subject" : "Test XML Message", - "id" : "id-1234-5678-9101", - "time" : "2020-09-23T06:23:21Z", - "datacontenttype" : "text/xml", - "data" : "User1user2hi" + "topic": "orders", + "pubsubname": "order_pub_sub", + "traceid": "00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01", + "tracestate": "", + "data" : "user2Order", + "id" : "id-1234-5678-9101", + "specversion" : "1.0", + "datacontenttype" : "text/xml", + "subject" : "Test XML Message", + "source" : "https://example.com/message", + "type" : "xml.message", + "time" : "2020-09-23T06:23:21Z" } ``` -## Override Dapr-generated CloudEvents values +## Replace Dapr generated CloudEvents values -Dapr automatically generates several CloudEvent properties. You can override these generated CloudEvent properties by providing the following optional metadata keys: +Dapr automatically generates several CloudEvent properties. You can replace these generated CloudEvent properties by providing the following optional metadata key/value: - `cloudevent-id`: overrides `id` - `cloudevent-source`: overrides `source` @@ -85,11 +89,11 @@ Dapr automatically generates several CloudEvent properties. You can override the - `cloudevent-tracestate`: overrides `tracestate` - `cloudevent-traceparent`: overrides `traceparent` -The CloudEvent override metadata properties apply globally for all pub/sub components. +The ability to replace CloudEvents properties using these metadata properties applies to all pub/sub components. ### Example -To override the `source` and `id` values from [the CloudEvent example above]({{< ref "#cloudevents-example" >}}) in code: +For example, to replace the `source` and `id` values from [the CloudEvent example above]({{< ref "#cloudevents-example" >}}) in code: {{< tabs "Python" ".NET" >}} @@ -97,7 +101,7 @@ To override the `source` and `id` values from [the CloudEvent example above]({{< ```python with DaprClient() as client: - for i in range(1, 10): + for i in range(1): order = {'orderId': i} # Publish an event/message using Dapr PubSub result = client.publish_event( @@ -113,7 +117,7 @@ with DaprClient() as client: {{% codetab %}} ```csharp -for (int i = 1; i <= 10; i++) { +for (int i = 1) { var order = new Order(i); using var client = new DaprClientBuilder().Build(); @@ -159,7 +163,7 @@ The JSON payload then reflects the new `source` and `id` values: ``` {{% alert title="Important" color="warning" %}} -While you can override `traceid`/`traceparent` and `tracestate`, doing this may interfere with tracing tools. It's recommended to use Open Telementry and Zipkin protocols for distributed traces. [Learn more about distributed tracing.]({{< ref tracing-overview.md >}}) +While you can replace `traceid`/`traceparent` and `tracestate`, doing this may interfere with tracing events and report inconsistent results in tracing tools. It's recommended to use Open Telementry for distributed traces. [Learn more about distributed tracing.]({{< ref tracing-overview.md >}}) {{% /alert %}} From ff1f2803dfc9d9c3137b3f7fd6080b81fe202e03 Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Fri, 30 Jun 2023 13:37:57 -0400 Subject: [PATCH 11/11] remove loop Signed-off-by: Hannah Hunter --- .../pubsub/pubsub-cloudevents.md | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md index 4c987bb3936..f7525632647 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md @@ -101,14 +101,13 @@ For example, to replace the `source` and `id` values from [the CloudEvent exampl ```python with DaprClient() as client: - for i in range(1): - order = {'orderId': i} - # Publish an event/message using Dapr PubSub - result = client.publish_event( - pubsub_name='order_pub_sub', - topic_name='orders', - publish_metadata={'cloudevent-id: 'd99b228f-6c73-4e78-8c4d-3f80a043d317', cloudevent-source: 'payment'} - ) + order = {'orderId': i} + # Publish an event/message using Dapr PubSub + result = client.publish_event( + pubsub_name='order_pub_sub', + topic_name='orders', + publish_metadata={'cloudevent-id: 'd99b228f-6c73-4e78-8c4d-3f80a043d317', cloudevent-source: 'payment'} + ) ``` {{% /codetab %}} @@ -117,22 +116,20 @@ with DaprClient() as client: {{% codetab %}} ```csharp -for (int i = 1) { - var order = new Order(i); - using var client = new DaprClientBuilder().Build(); +var order = new Order(i); +using var client = new DaprClientBuilder().Build(); - // Override cloudevent metadata - var metadata = new Dictionary() { - { "cloudevent.source", "payment" }, - { "cloudevent.id", "d99b228f-6c73-4e78-8c4d-3f80a043d317" } - } +// Override cloudevent metadata +var metadata = new Dictionary() { + { "cloudevent.source", "payment" }, + { "cloudevent.id", "d99b228f-6c73-4e78-8c4d-3f80a043d317" } +} - // Publish an event/message using Dapr PubSub - await client.PublishEventAsync("order_pub_sub", "orders", order, metadata); - Console.WriteLine("Published data: " + order); +// Publish an event/message using Dapr PubSub +await client.PublishEventAsync("order_pub_sub", "orders", order, metadata); +Console.WriteLine("Published data: " + order); - await Task.Delay(TimeSpan.FromSeconds(1)); -} +await Task.Delay(TimeSpan.FromSeconds(1)); ``` {{% /codetab %}}