How to subscribe/consume multiple topics from multiple subscriptions declaratively with Dapr pub/sub component?

67 views Asked by At

I have asked a similar question about how to do so programmatically with Dapr pub/sub component.

Dapr doc shows how to define a topic from a subscription, with its corresponding route declaratively in a yaml file.

Let's say if I have a subscription called subscription-1 and the topic I want to consume is called order-created-topic, I can define a yaml file like the following:

apiVersion: dapr.io/v2alpha1
kind: Subscription
metadata:
    name: subscription-1
spec:
    topic: order-created-topic
    routes:
        default: /api/orders
    pubsubname: dapr-pubsub-component

In the same folder structure, I have another yaml file for Dapr pub/sub component:

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
    name: dapr-pubsub-component
spec:
    type: pubsub.azure.servicebus.topics
    version: v1
    metadata:
    - name: connectionString
    value: [YOUR_SERVICE_BUS_CONNECTION_STRING]

You see the pubsubname dapr-pubsub-component in the subscription yaml file matches the one from the pub/sub component yaml file.

Lastly, I have the controller and action defined to match the route I defined in the subscription yaml file:

[ApiController]
[Route("api/orders")]
public class OrderController : ControllerBase
{
    [HttpPost("")]
    public IActionResult OrderCreated(OrderCreated @event)
    {
        ...
    }
}

Then when I run the Dapr command, everything is working fine.


My questions are:

  1. How can I support multiple topics from the same subscription?
    • From the subscription yaml file sample above, it seems like you can only define one topic per subscription per each yaml file.
  2. How can I support multiple different topics from different subscriptions?
    • I have tried defining multiple subscription yaml files and all point back to the same pubsuname. That didn't work.
  3. Is it possible to define the HTTP METHOD along with the routes in the subscription yaml file as well?
0

There are 0 answers