A Dapr pubsub component provides asynchronous message publication and consumption through a configured messaging backend. Applications call Dapr APIs instead of depending directly on a Kafka client, while the daprd sidecar connects to the selected implementation. section 7.3.5 section 7.3.2
In the Conference application, services publish events through the PubSub API, and a Dapr Subscription delivers events to the Frontend application. This removes Kafka-specific dependencies and leaves backend selection in component configuration. section 7.3.5
A working configuration connects the application workflow in four steps:
- Define a Dapr Component with a name such as conference-pubsub and a pubsub implementation such as pubsub.kafka. section 7.3.5
- Supply backend metadata, including the Kafka broker address and authentication mode. section 7.3.5
- Publish an event by passing the pubsub name, topic, and serialized event payload to the Dapr SDK. section 7.3.5
- Define a Subscription with the pubsub name, topic, HTTP route, and consuming application scope. section 7.3.5
Conference event flow
The services use conference-pubsub to exchange events on events-topic. A frontend-subscription routes those events to /api/new-events/ and scopes delivery to the frontend application. The application code retains the same messaging abstraction if the backend changes to RabbitMQ or a cloud provider service. section 7.3.5
Listing 7.2 Dapr PubSub component definition
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: conference-pubsub
spec:
type: pubsub.kafka
version: v1
metadata:
- name: brokers #1
value: kafka.default.svc.cluster.local:9092
- name: authType #2
value: "none"
Inspect the component manifest showing the Kafka type, version, broker address, and authentication metadata. section 7.3.5
Listing 7.3 Dapr Subscription definition
apiVersion: dapr.io/v1alpha1 kind: Subscription metadata: name: frontend-subscription spec: pubsubname: conference-pubsub #1 topic: events-topic #2 route: /api/new-events/ #3 scopes: - frontend #4
Inspect the subscription manifest showing how a topic is routed to a scoped application. section 7.3.5
