mirror of https://github.com/dapr/docs.git
Merge branch 'v1.14' into endgame_v1.14-updates
This commit is contained in:
commit
2d973d680d
|
@ -20,7 +20,7 @@ Not using CloudEvents disables support for tracing, event deduplication per mess
|
|||
|
||||
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.
|
||||
|
||||
{{< tabs curl "Python SDK" "PHP SDK">}}
|
||||
{{< tabs curl ".NET" "Python" "PHP">}}
|
||||
|
||||
{{% codetab %}}
|
||||
```bash
|
||||
|
@ -28,6 +28,43 @@ curl -X "POST" http://localhost:3500/v1.0/publish/pubsub/TOPIC_A?metadata.rawPay
|
|||
```
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```csharp
|
||||
using Dapr.Client;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddControllers().AddDapr();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapPost("/publish", async (DaprClient daprClient) =>
|
||||
{
|
||||
var message = new Message(
|
||||
Guid.NewGuid().ToString(),
|
||||
$"Hello at {DateTime.UtcNow}",
|
||||
DateTime.UtcNow
|
||||
);
|
||||
|
||||
await daprClient.PublishEventAsync(
|
||||
"pubsub", // pubsub name
|
||||
"messages", // topic name
|
||||
message, // message data
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
{ "rawPayload", "true" },
|
||||
{ "content-type", "application/json" }
|
||||
}
|
||||
);
|
||||
|
||||
return Results.Ok(message);
|
||||
});
|
||||
|
||||
app.Run();
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
```python
|
||||
from dapr.clients import DaprClient
|
||||
|
@ -74,9 +111,52 @@ Dapr apps are also able to subscribe to raw events coming from existing pub/sub
|
|||
|
||||
### Programmatically subscribe to raw events
|
||||
|
||||
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.
|
||||
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`.
|
||||
|
||||
{{< tabs "Python" "PHP SDK" >}}
|
||||
{{< tabs ".NET" "Python" "PHP" >}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```csharp
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapGet("/dapr/subscribe", () =>
|
||||
{
|
||||
var subscriptions = new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
pubsubname = "pubsub",
|
||||
topic = "messages",
|
||||
route = "/messages",
|
||||
metadata = new Dictionary<string, string>
|
||||
{
|
||||
{ "isRawPayload", "true" },
|
||||
{ "content-type", "application/json" }
|
||||
}
|
||||
}
|
||||
};
|
||||
return Results.Ok(subscriptions);
|
||||
});
|
||||
|
||||
app.MapPost("/messages", async (HttpContext context) =>
|
||||
{
|
||||
using var reader = new StreamReader(context.Request.Body);
|
||||
var json = await reader.ReadToEndAsync();
|
||||
|
||||
Console.WriteLine($"Raw message received: {json}");
|
||||
|
||||
return Results.Ok();
|
||||
});
|
||||
|
||||
app.Run();
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
|
@ -151,7 +231,7 @@ spec:
|
|||
default: /dsstatus
|
||||
pubsubname: pubsub
|
||||
metadata:
|
||||
rawPayload: "true"
|
||||
isRawPayload: "true"
|
||||
scopes:
|
||||
- app1
|
||||
- app2
|
||||
|
@ -161,4 +241,5 @@ scopes:
|
|||
|
||||
- Learn more about [publishing and subscribing messages]({{< ref pubsub-overview.md >}})
|
||||
- List of [pub/sub components]({{< ref supported-pubsub >}})
|
||||
- Read the [API reference]({{< ref pubsub_api.md >}})
|
||||
- Read the [API reference]({{< ref pubsub_api.md >}})
|
||||
- Read the .NET sample on how to [consume Kafka messages without CloudEvents](https://github.com/dapr/samples/pubsub-raw-payload)
|
|
@ -439,13 +439,11 @@ app.MapPost("/orders", (Order order) =>
|
|||
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.
|
||||
|
||||
```csharp
|
||||
var client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
|
||||
var client = DaprClient.CreateInvokeHttpClient(appId: "order-processor");
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
client.DefaultRequestHeaders.Add("dapr-app-id", "order-processor");
|
||||
|
||||
var response = await client.PostAsync($"{baseURL}/orders", content);
|
||||
Console.WriteLine("Order passed: " + order);
|
||||
var response = await client.PostAsJsonAsync("/orders", order, cts.Token);
|
||||
Console.WriteLine("Order passed: " + order);
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
@ -1089,13 +1087,11 @@ dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- dotnet r
|
|||
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.
|
||||
|
||||
```csharp
|
||||
var client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
|
||||
var client = DaprClient.CreateInvokeHttpClient(appId: "order-processor");
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
client.DefaultRequestHeaders.Add("dapr-app-id", "order-processor");
|
||||
|
||||
var response = await client.PostAsync($"{baseURL}/orders", content);
|
||||
Console.WriteLine("Order passed: " + order);
|
||||
var response = await client.PostAsJsonAsync("/orders", order, cts.Token);
|
||||
Console.WriteLine("Order passed: " + order);
|
||||
```
|
||||
|
||||
### Step 5: Use with Multi-App Run
|
||||
|
|
|
@ -149,7 +149,7 @@ services:
|
|||
- type: tmpfs
|
||||
target: /data
|
||||
tmpfs:
|
||||
size: "10000"
|
||||
size: "64m"
|
||||
|
||||
networks:
|
||||
hello-dapr: null
|
||||
|
|
|
@ -19,8 +19,8 @@ data:
|
|||
zpages:
|
||||
endpoint: :55679
|
||||
exporters:
|
||||
logging:
|
||||
loglevel: debug
|
||||
debug:
|
||||
verbosity: detailed
|
||||
# Depending on where you want to export your trace, use the
|
||||
# correct OpenTelemetry trace exporter here.
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue