PubSub
PubSub is a Dapr building block that enables you to publish and subscribe to messages between microservices. It decouples producers and consumers, allowing you to build scalable, event-driven systems.
Key Features
- Supports multiple messaging backends (Azure Service Bus, Kafka, Redis, etc.)
- Decouples services for improved scalability
- At-least-once delivery guarantees
- Dead-letter and retry support
Example Usage
- C#
- Java
- Python
// Publish an event using Dapr client
var client = new DaprClientBuilder().Build();
await client.PublishEventAsync("pubsub", "orders", orderData);
// Publish an event using Dapr client
DaprClient client = new DaprClientBuilder().build();
client.publishEvent("pubsub", "orders", orderData).block();
# Publish an event using Dapr client
from dapr.clients import DaprClient
with DaprClient() as client:
client.publish_event(pubsub_name='pubsub', topic_name='orders', data=order_data)
Real-World Application
You use PubSub to connect services that need to react to events, such as order creation, payment processing, or notifications. This pattern improves system resilience and scalability.
Related Links
Was this page useful?