Add more docs

Signed-off-by: Shubham Sharma <shubhash@microsoft.com>
This commit is contained in:
Shubham Sharma 2023-01-05 11:22:02 +05:30
parent 58eb6d6003
commit 6671a6e6ba
5 changed files with 147 additions and 8 deletions

View File

@ -1,11 +1,137 @@
---
type: docs
title: "Publishing & subscribing messages in bulk"
linkTitle: "Bulk messages"
weight: 2100
description: "Learn how to send and receive multiple messages at once"
title: "Send and receive messages in bulk"
linkTitle: "Send and receive messages in bulk"
weight: 7100
description: "Learn how to use the bulk publish and subscribe APIs in Dapr."
---
insert-introduction
{{% alert title="alpha" color="warning" %}}
The bulk publish and subscribe APIs are in **alpha** stage.
{{% /alert %}}
## Publishing messages in bulk
With the bulk publish and subscribe APIs, you can send and receive multiple messages in a single request.
## Native bulk publish and subscribe support
When a pub/sub component supports the bulk publish API natively, Dapr also publishes messages to the underlying pub/sub component in bulk.
Otherwise, Dapr falls back to sending messages one by one to the underlying pub/sub component. This is still more efficient than using the regular publish API, because applications can still send multiple messages in a single request to Dapr.
## Supported components
Refer [component reference]({{< ref supported-pubsub >}}) to see which components support the bulk publish API natively.
## Publishing messages in bulk
### Example
{{< tabs Javascript "HTTP API (Bash)" "HTTP API (PowerShell)" >}}
{{% codetab %}}
```typescript
import { DaprClient } from "@dapr/dapr";
const pubSubName = "my-pubsub-name";
const topic = "topic-a";
async function start() {
const client = new DaprClient();
// Publish multiple messages to a topic.
await client.pubsub.publishBulk(pubSubName, topic, ["message 1", "message 2", "message 3"]);
// Publish multiple messages to a topic with explicit bulk publish messages.
const bulkPublishMessages = [
{
entryID: "entry-1",
contentType: "application/json",
event: { hello: "foo message 1" },
},
{
entryID: "entry-2",
contentType: "application/cloudevents+json",
event: {
specversion: "1.0",
source: "/some/source",
type: "example",
id: "1234",
data: "foo message 2",
datacontenttype: "text/plain"
},
},
{
entryID: "entry-3",
contentType: "text/plain",
event: "foo message 3",
},
];
await client.pubsub.publishBulk(pubSubName, topic, bulkPublishMessages);
}
start().catch((e) => {
console.error(e);
process.exit(1);
});
```
{{% /codetab %}}
{{% codetab %}}
```bash
curl -X POST http://localhost:3500/v1.0-alpha1/publish/bulk/my-pubsub-name/topic-a \
-H 'Content-Type: application/json' \
-d '[
{
"entryId": "ae6bf7c6-4af2-11ed-b878-0242ac120002",
"event": "first",
"contentType": "text/plain"
},
{
"entryId": "b1f40bd6-4af2-11ed-b878-0242ac120002",
"event": {
"message": "second"
},
"contentType": "application/json"
},
]'
```
{{% /codetab %}}
{{% codetab %}}
```powershell
Invoke-RestMethod -Method Post -ContentType 'application/json' -Uri 'http://localhost:3500/v1.0-alpha1/publish/bulk/my-pubsub-name/topic-a' `
-Body '[
{
"entryId": "ae6bf7c6-4af2-11ed-b878-0242ac120002",
"event": "first",
"contentType": "text/plain"
},
{
"entryId": "b1f40bd6-4af2-11ed-b878-0242ac120002",
"event": {
"message": "second"
},
"contentType": "application/json"
},
]'
```
{{% /codetab %}}
{{< /tabs >}}
```
{{% /codetab %}}
{{< /tabs >}}
## Related links
- List of [supported pub/sub components]({{< ref supported-pubsub >}})
- Read the [API reference]({{< ref pubsub_api.md >}})

View File

@ -119,9 +119,9 @@ By default, all topic messages associated with an instance of a pub/sub componen
Dapr can set a timeout message on a per-message basis, meaning that if the message is not read from the pub/sub component, then the message is discarded. This timeout message prevents a build up of unread messages. If a message has been in the queue longer than the configured TTL, it is marked as dead. For more information, read [pub/sub message TTL]({{< ref pubsub-message-ttl.md >}}).
### Bulk messages
### Send and receive messages in bulk
Dapr supports sending and receiving multiple messages in a single request. This is useful for applications that need to send or receive a large number of messages at once. For more information, read [pub/sub bulk messages]({{< ref pubsub-bulk.md >}}).
Dapr supports sending and receiving multiple messages in a single request. This is useful for applications that require a high throughput. For more information, read [pub/sub bulk messages]({{< ref pubsub-bulk.md >}}).
## Try out pub/sub

View File

@ -3,8 +3,14 @@
state: Stable
version: v1
since: "1.8"
features:
bulkPublish: true
bulkSubscribe: false
- component: Azure Service Bus
link: setup-azure-servicebus
state: Stable
version: v1
since: "1.0"
features:
bulkPublish: true
bulkSubscribe: true

View File

@ -13,6 +13,9 @@
state: Stable
version: v1
since: "1.5"
features:
bulkPublish: true
bulkSubscribe: true
- component: Redis Streams
link: setup-redis-pubsub
state: Stable

View File

@ -10,6 +10,8 @@
<table width="100%">
<tr>
<th>Component</th>
<th>Bulk Publish</th>
<th>Bulk Subscribe</th>
<th>Status</th>
<th>Component version</th>
<th>Since runtime version</th>
@ -19,6 +21,8 @@
<td><a href="/reference/components-reference/supported-pubsub/{{ .link }}/" }}>{{ .component
}}</a>
</td>
<td align="center">{{ if .features.bulkPublish }}✅{{else}}<img src="/images/emptybox.png">{{ end }}</td>
<td align="center">{{ if .features.bulkSubscribe }}✅{{else}}<img src="/images/emptybox.png">{{ end }}</td>
<td>{{ .state }}</td>
<td>{{ .version }}</td>
<td>{{ .since }}</td>