Ana içeriğe geç

Dapr PubSub Task (Type: 4)

Dapr PubSub Task, Dapr publish/subscribe özelliği kullanarak event-driven messaging yapısı için kullanılan görev türüdür. Asenkron mesajlaşma ve loose coupling sağlar.

Görev Tanımı

Schema: task-definition.schema.json

{
"key": "publish-user-event",
"version": "1.0.0",
"domain": "core",
"flow": "sys-tasks",
"flowVersion": "1.0.0",
"tags": ["pubsub", "messaging", "event"],
"attributes": {
"type": "4",
"config": {
"pubSubName": "messagebus",
"topic": "user-events",
"data": {
"eventType": "UserRegistered",
"userId": "user-123"
},
"metadata": {
"priority": "high",
"source": "user-service"
}
}
}
}

Konfigürasyon Alanları

AlanTipZorunluVarsayılanAçıklama
pubSubNamestringEvet-PubSub component adı
topicstringEvet-Mesajın gönderileceği topic
dataobjectHayır-Mesaj içeriği
metadataobjectHayır-Mesaj metadata'sı

Property Erişimi

PropertySetter MetoduAçıklama
PubSubNameSetPubSubName(string pubSubName)PubSub component adı
TopicSetTopic(string topic)Hedef topic
DataSetData(dynamic data)Mesaj verisi
MetadataSetMetadata(Dictionary<string, string?> metadata)Mesaj metadata'sı

Desteklenen Message Broker'lar

Redis Streams

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: redis-pubsub
spec:
type: pubsub.redis
version: v1
metadata:
- name: redisHost
value: "redis:6379"

Apache Kafka

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: kafka-pubsub
spec:
type: pubsub.kafka
version: v1
metadata:
- name: brokers
value: "kafka:9092"

RabbitMQ

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: rabbitmq-pubsub
spec:
type: pubsub.rabbitmq
version: v1
metadata:
- name: host
value: "amqp://rabbitmq:5672"
- name: durable
value: "true"

Azure Service Bus

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: servicebus-pubsub
spec:
type: pubsub.azure.servicebus
version: v1
metadata:
- name: connectionString
secretKeyRef:
name: servicebus-secret
key: connectionString

Standart Yanıt

{
"data": {
"Published": true,
"Message": "Event published successfully"
},
"isSuccess": true,
"errorMessage": null,
"metadata": {
"PubSubName": "messagebus",
"Topic": "user-events"
},
"executionDurationMs": 45,
"taskType": "DaprPubSub"
}

Sık Karşılaşılan Sorunlar

ProblemÇözüm
PubSub component not foundPubSub component configuration ve app ID'yi kontrol edin
Topic configuration errorTopic name ve pubsub component uyumunu kontrol edin
Message serialization failedSetData metoduna valid object geçtiğinizden emin olun
Metadata format errorSetMetadata metoduna Dictionary<string, string?> formatında data gönderin