mirror of https://github.com/dapr/docs.git
Added an example for DotNet bulk subscribing (#3281)
* Added an example for DotNet bulk subscribing Signed-off-by: Sabrina Shepherd <sabrina@nuqleous.com> * Update daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-bulk.md Signed-off-by: Sabrina Shepherd <sabrinashepherd@outlook.com> * Update daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-bulk.md Signed-off-by: Mark Fussell <markfussell@gmail.com> --------- Signed-off-by: Sabrina Shepherd <sabrina@nuqleous.com> Signed-off-by: Sabrina Shepherd <sabrinashepherd@outlook.com> Signed-off-by: Mark Fussell <markfussell@gmail.com> Co-authored-by: Mark Fussell <markfussell@gmail.com>
This commit is contained in:
parent
4ffbc22527
commit
c0d1e6a931
|
|
@ -334,7 +334,7 @@ Please refer [Expected HTTP Response for Bulk Subscribe]({{< ref pubsub_api.md >
|
||||||
|
|
||||||
Please refer following code samples for how to use Bulk Subscribe:
|
Please refer following code samples for how to use Bulk Subscribe:
|
||||||
|
|
||||||
{{< tabs Java Javascript "HTTP API (Bash)" "HTTP API (PowerShell)" >}}
|
{{< tabs "Java" "JavaScript" ".NET" "HTTP API (Bash)" "HTTP API (PowerShell)" >}}
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
|
|
@ -406,6 +406,56 @@ async function start() {
|
||||||
|
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
||||||
|
{{% codetab %}}
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Dapr.AspNetCore;
|
||||||
|
using Dapr;
|
||||||
|
|
||||||
|
namespace DemoApp.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class BulkMessageController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ILogger<BulkMessageController> logger;
|
||||||
|
|
||||||
|
public BulkMessageController(ILogger<BulkMessageController> logger)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BulkSubscribe("messages", 10, 10)]
|
||||||
|
[Topic("pubsub", "messages")]
|
||||||
|
public ActionResult<BulkSubscribeAppResponse> HandleBulkMessages([FromBody] BulkSubscribeMessage<BulkMessageModel<BulkMessageModel>> bulkMessages)
|
||||||
|
{
|
||||||
|
List<BulkSubscribeAppResponseEntry> responseEntries = new List<BulkSubscribeAppResponseEntry>();
|
||||||
|
logger.LogInformation($"Received {bulkMessages.Entries.Count()} messages");
|
||||||
|
foreach (var message in bulkMessages.Entries)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
logger.LogInformation($"Received a message with data '{message.Event.Data.MessageData}'");
|
||||||
|
responseEntries.Add(new BulkSubscribeAppResponseEntry(message.EntryId, BulkSubscribeAppResponseStatus.SUCCESS));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.LogError(e.Message);
|
||||||
|
responseEntries.Add(new BulkSubscribeAppResponseEntry(message.EntryId, BulkSubscribeAppResponseStatus.RETRY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new BulkSubscribeAppResponse(responseEntries);
|
||||||
|
}
|
||||||
|
public class BulkMessageModel
|
||||||
|
{
|
||||||
|
public string MessageData { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% /codetab %}}
|
||||||
|
|
||||||
{{< /tabs >}}
|
{{< /tabs >}}
|
||||||
## How components handle publishing and subscribing to bulk messages
|
## How components handle publishing and subscribing to bulk messages
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue