- Home
- Skills
- Mjunaidca
- Mjs Agent Skills
- Dapr Integration
dapr-integration_skill
- Python
19
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill mjunaidca/mjs-agent-skills --skill dapr-integration- skill.md9.0 KB
Overview
This skill integrates Dapr sidecars for pub/sub messaging and scheduled jobs in Python services. It provides reusable patterns for FastAPI subscription handlers, CloudEvent unwrapping, publishing events, and using the Dapr Jobs API with correct callback routes. The content focuses on practical code patterns and common pitfalls to avoid.
How this skill works
The skill inspects incoming HTTP requests from Dapr, unwraps CloudEvent envelopes to extract payloads, and routes events to application handlers. It shows how to publish events to the Dapr HTTP API, schedule and delete jobs via the Jobs API, and implement the job callback endpoint that Dapr invokes. It also includes tips for local and Kubernetes deployments and debugging sidecar logs.
When to use it
- Building event-driven microservices that rely on Dapr pub/sub.
- Scheduling one-time or recurring work using Dapr Jobs API (v1.0-alpha1).
- Implementing FastAPI endpoints that must accept Dapr CloudEvents.
- Debugging Dapr sidecar integration, subscriptions, or job callbacks.
- Publishing events from Python code to a Dapr-backed pub/sub component.
Best practices
- Always unwrap the CloudEvent envelope: use raw.get('data', raw) before accessing payload fields.
- Return {"status":"SUCCESS"} from pub/sub handlers even on error to avoid Dapr retries for irrecoverable failures.
- Expose the exact job callback route /job/{job_name} because Dapr Jobs uses that pattern by default.
- Use localhost:3500 as the Dapr HTTP endpoint in both local and sidecar contexts.
- Log exceptions but avoid raising them to Dapr for event handlers; handle retries explicitly when needed.
Example use cases
- Subscribe to a task-events topic in FastAPI and process task.created messages after unwrapping CloudEvents.
- Publish notification events from a service using the Dapr HTTP publish endpoint for cross-service delivery.
- Schedule reminder jobs via the Dapr Jobs API and implement /job/{job_name} to perform the reminder action.
- Deploy services in Kubernetes with dapr.io annotations and a Redis pub/sub component for production messaging.
- Debug failing subscriptions by calling /dapr/subscribe and reviewing the daprd container logs for scheduler or HTTP errors.
FAQ
Dapr wraps pub/sub messages in the CloudEvent envelope and your payload lives under the data field; accessing event_type or nested data without unwrapping will return None.
What route does Dapr call for scheduled jobs?
Dapr Jobs v1.0-alpha1 calls POST /job/{job_name} by default, so implement that route rather than a custom endpoint.