dotnet-sdk icon indicating copy to clipboard operation
dotnet-sdk copied to clipboard

Issue with Consumer ID in Dapr Topic Subscription

Open mshashi0306 opened this issue 1 year ago • 6 comments

I'm working with a Dapr application, and I'm having trouble with my topic subscription setup in the following code:

builder.MapControllerRoute("ReceiveFeedEvent", "/ReceiveFeedEvent").WithTopic(new TopicOptions { PubsubName = Config.DaprAlertFeedConsumerName, Name = configuration[Config.AlertFeedTopicNameKey], Metadata = new Dictionary<string, string>() { { "consumerID","feed"} } });

I'm using this configuration to set up a route that receives events from a specified topic. However, it seems that the consumerID I specified in the metadata does not work as expected.

Kindly help if there is a specific format or requirement for the consumerID in Dapr subscriptions?

I am trying to subscribe multiple subscription under one topic using Dapr.

mshashi0306 avatar Oct 14 '24 14:10 mshashi0306

@mshashi0306 I believe the consumer ID should be populated in the YAML component's metadata field as indicated in the Azure Service Bus Topic component spec, not in the topic options in the C# project.

WhitWaldo avatar Oct 14 '24 17:10 WhitWaldo

@mshashi0306 Have you had an opportunity to try out my suggestion?

WhitWaldo avatar Oct 17 '24 17:10 WhitWaldo

Yes @WhitWaldo , I have tried adding the consumerId to the YAML file, but it requires creating multiple service bus component files for each subscription.

I’m looking to have a single YAML file without the consumerId, as I have multiple subscriptions under one topic.

Could you please help with this?

mshashi0306 avatar Oct 18 '24 04:10 mshashi0306

I've raised your question on Discord in hopes someone there knows as I'm afraid I don't immediately see how you'd pass the consumer ID in any but a declarative instance.

WhitWaldo avatar Oct 18 '24 08:10 WhitWaldo

@mshashi0306 : What's the problem you are encountering? You don't receive messages in your subscription handler? I've run a sample also with Azure Service Bus, that worked for me. Configuring the metadata like that with the consumerID should be fine.

Have you tried using a minimal API like below?

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.UseRouting();
app.UseCloudEvents();
app.MapSubscribeHandler();

app.MapPost("ReceiveFeedEvent", "/ReceiveFeedEvent")
  .WithTopic(new TopicOptions { 
     PubsubName = Config.DaprAlertFeedConsumerName, 
     Name = configuration[Config.AlertFeedTopicNameKey], 
     Metadata = new Dictionary<string, string>() { { "consumerID","feed"} } 
  });

app.Run();

Also note the MapSubscribeHandler code. If you forget that, the Dapr sidecar won't know on which endpoint to call your subscription handler.

ngruson avatar Jan 16 '25 17:01 ngruson

@mshashi0306 Is this still an issue you're experiencing or would you mind if I closed out the issue?

WhitWaldo avatar Mar 13 '25 01:03 WhitWaldo