0

So I've created a resource pubsub.yaml which references a Service Bus Connection String. It works fine on my local machine using .NET Aspire, however when I use the az up (Container Apps) it fails. In the Aspire Dashboard I can see the daprstore is running but the service itself is stuck on a pending state. In Container Apps I can also see that the Dapr Components is set to redis instead of Service Bus. Any idea what's going wrong?

I tried the following code below:

var pubSub = builder.AddDaprPubSub("pubsub");

var apiService = builder.AddProject<Projects.SomeService>("someservice")
    .WithDaprSidecar()
    .WithReference(pubSub);

builder.Build().Run();

Service Bus YAML:

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: pubsub
spec:
  type: pubsub.azure.servicebus
  version: v1
  metadata:
  - name: connectionString
    value: "Endpoint=someEndPoint"
  - name: topic
    value: "someTopic"
  - name: subscriptionName
    value: "someSubscriptionName"
2
  • refer to this link for Azure Service Bus binding spec Commented Jan 12 at 2:58
  • @Sampath Thank you for your response! I see that's focused on reading the queue, is there also a way to work with the pubsub pattern? So when a message is published, there is a subscriber immediately acting on it? Also what is the difference with my current scenario versus binding? Commented Jan 13 at 9:10

1 Answer 1

0

The issue arises because the Dapr component configuration (e.g., pubsub.yaml) referencing Azure Service Bus is not correctly applied during deployment to Azure Container Apps, causing Dapr to default to Redis.

To resolve this, Use below Azure CLI command to deploy using custom pubsub.yaml:

az containerapp dapr-component create \
    --name pubsub \
    --containerapp my-container-app \
    --yaml ./pubsub.yaml

In pubsub.yaml, securely reference the Service Bus connection string using a secret:

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: pubsub
spec:
  type: pubsub.azure.servicebus
  version: v1
  metadata:
  - name: connectionString
    secretKeyRef: servicebus-connection-string
  - name: topic
    value: "someTopic"
  - name: subscriptionName
    value: "someSubscriptionName"
auth:
  secretStore: secrets

Add the secret to the Container Apps environment:

az containerapp secret set \
    --name my-container-app \
    --resource-group my-resource-group \
    --secrets servicebus-connection-string="Endpoint=your-endpoint"

Update the .NET code to use the pub/sub name:

var pubSub = builder.AddDaprPubSub("pubsub");

After deployment, verify that the custom Dapr configuration is active and messages are sent/received via Service Bus. Use az containerapp logs show or Dapr monitoring tools to confirm.

Console output:

enter image description here

Refer this MSDOC for Running Microservices with Dapr on Azure Container Apps] and Connect to Azure services via Dapr components in the Azure portal

Yes, it is possible to use the pub/sub pattern with Azure Service Bus and Dapr, where a message is published and immediately handled by a subscriber.

The pub/sub pattern is different from a binding in how messages are handled and processed by the application. So the Other way is to use az containerapp env dapr-component you can refer this MSDOC to deploy with yml.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.