Skip to content

Commit 870aeac

Browse files
authored
Merge pull request #4530 from hhunter-ms/upmerge_02-12
Upmerge - Feb 12
2 parents 0fed40f + 65ada85 commit 870aeac

File tree

6 files changed

+145
-43
lines changed

6 files changed

+145
-43
lines changed

daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-raw.md

+86-5
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,51 @@ Not using CloudEvents disables support for tracing, event deduplication per mess
2020

2121
To disable CloudEvent wrapping, set the `rawPayload` metadata to `true` as part of the publishing request. This allows subscribers to receive these messages without having to parse the CloudEvent schema.
2222

23-
{{< tabs curl "Python SDK" "PHP SDK">}}
23+
{{< tabs curl ".NET" "Python" "PHP">}}
2424

2525
{{% codetab %}}
2626
```bash
2727
curl -X "POST" http://localhost:3500/v1.0/publish/pubsub/TOPIC_A?metadata.rawPayload=true -H "Content-Type: application/json" -d '{"order-number": "345"}'
2828
```
2929
{{% /codetab %}}
3030

31+
{{% codetab %}}
32+
33+
```csharp
34+
using Dapr.Client;
35+
36+
var builder = WebApplication.CreateBuilder(args);
37+
builder.Services.AddControllers().AddDapr();
38+
39+
var app = builder.Build();
40+
41+
app.MapPost("/publish", async (DaprClient daprClient) =>
42+
{
43+
var message = new Message(
44+
Guid.NewGuid().ToString(),
45+
$"Hello at {DateTime.UtcNow}",
46+
DateTime.UtcNow
47+
);
48+
49+
await daprClient.PublishEventAsync(
50+
"pubsub", // pubsub name
51+
"messages", // topic name
52+
message, // message data
53+
new Dictionary<string, string>
54+
{
55+
{ "rawPayload", "true" },
56+
{ "content-type", "application/json" }
57+
}
58+
);
59+
60+
return Results.Ok(message);
61+
});
62+
63+
app.Run();
64+
```
65+
66+
{{% /codetab %}}
67+
3168
{{% codetab %}}
3269
```python
3370
from dapr.clients import DaprClient
@@ -74,9 +111,52 @@ Dapr apps are also able to subscribe to raw events coming from existing pub/sub
74111

75112
### Programmatically subscribe to raw events
76113

77-
When subscribing programmatically, add the additional metadata entry for `rawPayload` so the Dapr sidecar automatically wraps the payloads into a CloudEvent that is compatible with current Dapr SDKs.
114+
When subscribing programmatically, add the additional metadata entry for `rawPayload` to allow the subscriber to receive a message that is not wrapped by a CloudEvent. For .NET, this metadata entry is called `isRawPayload`.
115+
116+
{{< tabs ".NET" "Python" "PHP" >}}
117+
118+
{{% codetab %}}
119+
120+
```csharp
121+
using System.Text.Json;
122+
using System.Text.Json.Serialization;
123+
124+
var builder = WebApplication.CreateBuilder(args);
125+
var app = builder.Build();
126+
127+
app.MapGet("/dapr/subscribe", () =>
128+
{
129+
var subscriptions = new[]
130+
{
131+
new
132+
{
133+
pubsubname = "pubsub",
134+
topic = "messages",
135+
route = "/messages",
136+
metadata = new Dictionary<string, string>
137+
{
138+
{ "isRawPayload", "true" },
139+
{ "content-type", "application/json" }
140+
}
141+
}
142+
};
143+
return Results.Ok(subscriptions);
144+
});
145+
146+
app.MapPost("/messages", async (HttpContext context) =>
147+
{
148+
using var reader = new StreamReader(context.Request.Body);
149+
var json = await reader.ReadToEndAsync();
150+
151+
Console.WriteLine($"Raw message received: {json}");
78152

79-
{{< tabs "Python" "PHP SDK" >}}
153+
return Results.Ok();
154+
});
155+
156+
app.Run();
157+
```
158+
159+
{{% /codetab %}}
80160

81161
{{% codetab %}}
82162

@@ -151,7 +231,7 @@ spec:
151231
default: /dsstatus
152232
pubsubname: pubsub
153233
metadata:
154-
rawPayload: "true"
234+
isRawPayload: "true"
155235
scopes:
156236
- app1
157237
- app2
@@ -161,4 +241,5 @@ scopes:
161241
162242
- Learn more about [publishing and subscribing messages]({{< ref pubsub-overview.md >}})
163243
- List of [pub/sub components]({{< ref supported-pubsub >}})
164-
- Read the [API reference]({{< ref pubsub_api.md >}})
244+
- Read the [API reference]({{< ref pubsub_api.md >}})
245+
- Read the .NET sample on how to [consume Kafka messages without CloudEvents](https://github.com/dapr/samples/pubsub-raw-payload)

daprdocs/content/en/developing-applications/integrations/AWS/authenticating-aws.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,16 @@ In production scenarios, it is recommended to use a solution such as:
8080

8181
If running on AWS EKS, you can [link an IAM role to a Kubernetes service account](https://docs.aws.amazon.com/eks/latest/userguide/create-service-account-iam-policy-and-role.html), which your pod can use.
8282

83-
All of these solutions solve the same problem: They allow the Dapr runtime process (or sidecar) to retrive credentials dynamically, so that explicit credentials aren't needed. This provides several benefits, such as automated key rotation, and avoiding having to manage secrets.
83+
All of these solutions solve the same problem: They allow the Dapr runtime process (or sidecar) to retrieve credentials dynamically, so that explicit credentials aren't needed. This provides several benefits, such as automated key rotation, and avoiding having to manage secrets.
8484

8585
Both Kiam and Kube2IAM work by intercepting calls to the [instance metadata service](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html).
8686

87+
### Setting Up Dapr with AWS EKS Pod Identity
88+
89+
EKS Pod Identities provide the ability to manage credentials for your applications, similar to the way that Amazon EC2 instance profiles provide credentials to Amazon EC2 instances. Instead of creating and distributing your AWS credentials to the containers or using the Amazon EC2 instance’s role, you associate an IAM role with a Kubernetes service account and configure your Pods to use the service account.
90+
91+
To see a comprehensive example on how to authorize pod access to AWS Secrets Manager from EKS using AWS EKS Pod Identity, [follow the sample in this repository](https://github.com/dapr/samples/tree/master/dapr-eks-podidentity).
92+
8793
### Use an instance profile when running in stand-alone mode on AWS EC2
8894

8995
If running Dapr directly on an AWS EC2 instance in stand-alone mode, you can use instance profiles.
@@ -130,7 +136,6 @@ On Windows, the environment variable needs to be set before starting the `dapr`
130136

131137
{{< /tabs >}}
132138

133-
134139
### Authenticate to AWS if using AWS SSO based profiles
135140

136141
If you authenticate to AWS using [AWS SSO](https://aws.amazon.com/single-sign-on/), some AWS SDKs (including the Go SDK) don't yet support this natively. There are several utilities you can use to "bridge the gap" between AWS SSO-based credentials and "legacy" credentials, such as:
@@ -157,7 +162,7 @@ AWS_PROFILE=myprofile awshelper daprd...
157162
<!-- windows -->
158163
{{% codetab %}}
159164

160-
On Windows, the environment variable needs to be set before starting the `awshelper` command, doing it inline (like in Linxu/MacOS) is not supported.
165+
On Windows, the environment variable needs to be set before starting the `awshelper` command; doing it inline (like in Linux/MacOS) is not supported.
161166

162167
{{% /codetab %}}
163168

@@ -169,4 +174,7 @@ On Windows, the environment variable needs to be set before starting the `awshel
169174

170175
## Related links
171176

172-
For more information, see [how the AWS SDK (which Dapr uses) handles credentials](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials).
177+
- For more information, see [how the AWS SDK (which Dapr uses) handles credentials](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials).
178+
- [EKS Pod Identity Documentation](https://docs.aws.amazon.com/eks/latest/userguide/pod-identities.html)
179+
- [AWS SDK Credentials Configuration](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials)
180+
- [Set up an Elastic Kubernetes Service (EKS) cluster](https://docs.dapr.io/operations/hosting/kubernetes/cluster/setup-eks/)

daprdocs/content/en/developing-applications/integrations/Diagrid/test-containers.md

-21
This file was deleted.

daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md

+8-12
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,11 @@ app.MapPost("/orders", (Order order) =>
442442
In the Program.cs file for the `checkout` service, you'll notice there's no need to rewrite your app code to use Dapr's service invocation. You can enable service invocation by simply adding the `dapr-app-id` header, which specifies the ID of the target service.
443443

444444
```csharp
445-
var client = new HttpClient();
446-
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
445+
var client = DaprClient.CreateInvokeHttpClient(appId: "order-processor");
446+
var cts = new CancellationTokenSource();
447447
448-
client.DefaultRequestHeaders.Add("dapr-app-id", "order-processor");
449-
450-
var response = await client.PostAsync($"{baseURL}/orders", content);
451-
Console.WriteLine("Order passed: " + order);
448+
var response = await client.PostAsJsonAsync("/orders", order, cts.Token);
449+
Console.WriteLine("Order passed: " + order);
452450
```
453451

454452
{{% /codetab %}}
@@ -1092,13 +1090,11 @@ dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- dotnet r
10921090
In the Program.cs file for the `checkout` service, you'll notice there's no need to rewrite your app code to use Dapr's service invocation. You can enable service invocation by simply adding the `dapr-app-id` header, which specifies the ID of the target service.
10931091

10941092
```csharp
1095-
var client = new HttpClient();
1096-
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
1097-
1098-
client.DefaultRequestHeaders.Add("dapr-app-id", "order-processor");
1093+
var client = DaprClient.CreateInvokeHttpClient(appId: "order-processor");
1094+
var cts = new CancellationTokenSource();
10991095

1100-
var response = await client.PostAsync($"{baseURL}/orders", content);
1101-
Console.WriteLine("Order passed: " + order);
1096+
var response = await client.PostAsJsonAsync("/orders", order, cts.Token);
1097+
Console.WriteLine("Order passed: " + order);
11021098
```
11031099

11041100
### Step 5: Use with Multi-App Run

daprdocs/content/en/operations/hosting/kubernetes/cluster/setup-eks.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ This guide walks you through installing an Elastic Kubernetes Service (EKS) clus
6666
1. Create the cluster by running the following command:
6767
6868
```bash
69-
eksctl create cluster -f cluster.yaml
69+
eksctl create cluster -f cluster-config.yaml
7070
```
7171

7272
1. Verify the kubectl context:

daprdocs/content/en/reference/components-reference/supported-pubsub/setup-azure-eventhubs.md

+38
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,44 @@ Entity management is only possible when using [Microsoft Entra ID Authentication
198198

199199
> Dapr passes the name of the consumer group to the Event Hub, so this is not supplied in the metadata.
200200

201+
## Receiving custom properties
202+
203+
By default, Dapr does not forward [custom properties](https://learn.microsoft.com/azure/event-hubs/add-custom-data-event). However, by setting the subscription metadata `requireAllProperties` to `"true"`, you can receive custom properties as HTTP headers.
204+
205+
```yaml
206+
apiVersion: dapr.io/v2alpha1
207+
kind: Subscription
208+
metadata:
209+
name: order-pub-sub
210+
spec:
211+
topic: orders
212+
routes:
213+
default: /checkout
214+
pubsubname: order-pub-sub
215+
metadata:
216+
requireAllProperties: "true"
217+
```
218+
219+
The same can be achieved using the Dapr SDK:
220+
221+
{{< tabs ".NET" >}}
222+
223+
{{% codetab %}}
224+
225+
```csharp
226+
[Topic("order-pub-sub", "orders")]
227+
[TopicMetadata("requireAllProperties", "true")]
228+
[HttpPost("checkout")]
229+
public ActionResult Checkout(Order order, [FromHeader] int priority)
230+
{
231+
return Ok();
232+
}
233+
```
234+
235+
{{% /codetab %}}
236+
237+
{{< /tabs >}}
238+
201239
## Subscribing to Azure IoT Hub Events
202240

203241
Azure IoT Hub provides an [endpoint that is compatible with Event Hubs](https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messages-read-builtin#read-from-the-built-in-endpoint), so the Azure Event Hubs pubsub component can also be used to subscribe to Azure IoT Hub events.

0 commit comments

Comments
 (0)