1

Dapr already allows us to subscribe multiple apps to a topic declaratively.

But can we use just one subscription.yaml file to subscribe an app to multiple topics declaratively?

Something like:

apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
  name: myevent-subscription
spec:
- topic: newOrder
  route: /orders
  pubsubname: pubsub
- topic: newProduct
  route: /productCatalog/products
  pubsubname: pubsub
scopes:
- myapp

I know how to subscribe an app to multiple topics programmatically, but "the declarative approach removes the Dapr dependency from your code and allows, for example, existing applications to subscribe to topics, without having to change code"¹ and it's what I want.

Ocimar
  • 53
  • 1
  • 6

1 Answers1

1

You should be able to have multiple Subscription entries in a single file, certainly for Kubernetes deployments, like this.

apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
  name: orders-subscription
spec:
  topic: newOrder
  route: /orders
  pubsubname: pubsub
scopes:
- app1
- app2

---

apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
  name: products-subscription
spec:
  topic: newProduct
  route: /productCatalog/products
  pubsubname: pubsub
scopes:
- app1
- app2
Thomas Freudenberg
  • 5,048
  • 1
  • 35
  • 44
  • 2
    ok ok you got me, you have just one file. But it seems a little verbose, doesn't it? It would be nice if there was another way – Ocimar May 21 '21 at 14:56
  • This seems to give an error "two identical subscriptions found" when your pubsub name is the same, even if everything else is different. Example, I want to publish to one topic and subscribe to another using this approach. – user3007447 Dec 05 '22 at 21:17