liveBook · Manning

Dapr pubsub component

As explained in Platform Engineering on Kubernetes

A Dapr pubsub component is a Dapr component that provides asynchronous message publication and consumption through a messaging backend.

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

How Platform Engineering on Kubernetes covers it

How deep it goes
Explains component and subscription configuration plus SDK publication, but stops short of detailing message-consumption implementation internals.
Examples
Uses the Conference application, conference-pubsub, events-topic, frontend-subscription, and the /api/new-events/ route.
What it assumes
Assumes familiarity with Dapr-enabled services and asynchronous messaging, while introducing backend configuration and subscriptions through concrete manifests.
What you can do after
Apply it via Dapr configuration and SDK calls to exchange asynchronous events without embedding a Kafka client in each service.
How it connects
Connects asynchronous messaging with Dapr components, subscriptions, daprd sidecars, Kafka, RabbitMQ, and cloud messaging services.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Platform Engineering on Kubernetes. The section links point to the parts of the book it draws on.