Issue with Consumer ID in Dapr Topic Subscription
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 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.
@mshashi0306 Have you had an opportunity to try out my suggestion?
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?
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.
@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.
@mshashi0306 Is this still an issue you're experiencing or would you mind if I closed out the issue?