본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Messaging

원문 보기 위키 갱신

Dapr.Messaging is the unified Dapr Publish/Subscribe messaging SDK for .NET. It brings all Dapr pub/sub functional modes—event publishing, streaming pull subscriptions, programmatic gRPC push subscriptions, and HTTP subscriptions—together into a single, modern package family. Rather than fragmenting pub/sub across Dapr.Client and Dapr.AspNetCore, Dapr.Messaging provides a clean, cohesive programming model built on top of modern .NET fundamentals: Roslyn source generators for reflection-free dispatch, compile-time Roslyn analyzers, and the standard Microsoft.Extensions.Options pattern.

Unified package architecture

Dapr.Messaging is a meta-package that brings the runtime client (Dapr.Messaging.Runtime), core abstractions (Dapr.Messaging.Abstractions), source generators (Dapr.Messaging.Generators), and Roslyn analyzers (Dapr.Messaging.Analyzers) in a single package reference:

<ItemGroup>
<PackageReference Include="Dapr.Messaging" Version="..." />
</ItemGroup>

출처: Dapr 문서

본문

What changed

The Dapr .NET SDK originally distributed messaging capabilities across multiple packages: Dapr.Client provided basic publish and dynamic streaming pull methods, while Dapr.AspNetCore handled controller-based and minimal API push subscriptions via HTTP endpoints. Dapr.Messaging unifies and modernizes this architecture:

  • Unified publishing and subscribing: Publish events with IDaprPublishSubscribeClient (including single events, raw byte streams, and bulk publishing) and author subscribers using a single ITopicHandler interface.

  • Three unified delivery modes: Subscriptions support DeliveryMode.Streaming (streaming subscriptions via gRPC), DeliveryMode.Programmatic (programmatic subscriptions via gRPC push), and DeliveryMode.Http (declarative subscriptions via /dapr/subscribe), all configured through the same [DaprTopic] attribute.

  • Source generators eliminate reflection: The Dapr.Messaging.Generators source generator inspects [DaprTopic] handlers at compile time and emits typed dispatchers, subscriber registries, and dependency injection wiring. No runtime reflection or runtime code generation is performed on the invocation path.

  • AOT and trimming considerations: Handler discovery and dispatch registration are generated at compile time, but the current generated subscriber dispatchers use runtime System.Text.Json metadata. Native AOT and trimming scenarios require explicit validation with the target SDK version.

  • Roslyn analyzers and diagnostics: The SDK includes compile-time analyzers (DAPR1610–DAPR1617) that catch misconfigurations directly in your IDE as you write code:DAPR1610 (Error): Conflicting delivery modes on the same topic.

  • DAPR1611 (Error): [DaprTopic] class not implementing ITopicHandler.

  • DAPR1612 (Warning): Unregistered message type in Native AOT compilation.

  • DAPR1613 (Warning): Missing app.MapDaprMessaging() for programmatic subscriptions (with CodeFix).

  • DAPR1614 (Warning): Direct invocation of internal DaprMessagingRegistration.

  • DAPR1615 (Warning): Endpoint mapping present without matching topic subscribers.

  • DAPR1616 (Warning): [DaprTopic] feature enabled without companion properties.

  • DAPR1617 (Warning): Ignored [DaprTopic] properties for the selected delivery mode or feature.

  • Standard options and simplified DI: Uses IOptions and a single services.AddDaprMessaging() method that registers options, the publishing client, source-generated subscriber dispatchers, and required hosting services in a single atomic operation.

Comparison with legacy pub/sub approaches

| Capability | Legacy (Dapr.Client / Dapr.AspNetCore) | Modern (Dapr.Messaging) | | Package structure | Split across Dapr.Client and Dapr.AspNetCore | Single unified meta-package Dapr.Messaging | | Publishing client | DaprClient.PublishEventAsync | Dedicated IDaprPublishSubscribeClient / DaprPublishSubscribeClient | | Bulk publishing | DaprClient.BulkPublishEventAsync | IDaprPublishSubscribeClient.BulkPublishEventAsync with typed BulkPublishEntry | | Subscriptions model | Controller attributes ([Topic]) or minimal API endpoints | Unified ITopicHandler handlers decorated with [DaprTopic] | | Delivery modes | Separate implementations for streaming gRPC vs HTTP | Configurable via DeliveryMode (Streaming, Programmatic, Http) | | Streaming pull subscriptions | Imperative client calls only | Both declarative [DaprTopic(Delivery = DeliveryMode.Streaming)] and imperative SubscribeAsync | | Dispatch mechanism | Runtime reflection / MVC action invokers | Source-generated typed dispatchers (AddDaprMessaging) | | Native AOT & Trimming | Not supported | Requires explicit validation | | Compile-time analyzers | None | Built-in Roslyn analyzers and code fixes (DAPR16xx) | | Configuration | Custom builder methods | Standard Microsoft.Extensions.Options pattern (DaprMessagingOptions) | | CloudEvents support | Manual deserialization or controller bindings | Strongly-typed CloudEvent, CloudEvent, and TopicContext.CloudEvent |

Core concepts

  • Tutorial: Dapr.Messaging by example: Seven runnable examples covering publishing, streaming, routing, bulk subscriptions, gRPC push, HTTP push, dynamic streaming, and their unit and integration testing patterns.
  • Publish events how-to: Step-by-step guide to publishing JSON events, CloudEvents, raw payloads, and bulk message batches using IDaprPublishSubscribeClient.
  • Subscribe to topics how-to: Step-by-step guide to authoring ITopicHandler subscribers, choosing delivery modes with [DaprTopic], compile-time source generation, dynamic streaming subscriptions, and compiler diagnostics.
  • Configuration and usage guide: Lifetime management, DI options configuration, advanced features (bulk pub/sub, dead-letter topics, CEL routing), and AOT/trimming considerations.

Next steps

  • Tutorial: Dapr.Messaging by example
  • How-To: Publish events with IDaprPublishSubscribeClient
  • How-To: Author subscriptions and handle topic messages
  • Dapr Messaging configuration and usage reference
  • Dapr Pub/Sub building block overview

Publish events Learn how to publish JSON events, CloudEvents, raw payloads, and bulk batches using IDaprPublishSubscribeClient in Dapr.Messaging Learn more → Subscribe to topics Learn how to author topic handlers, configure streaming, programmatic, and HTTP delivery modes, and wire up reflection-free dispatchers with Dapr.Messaging Learn more → Configuration and usage Configuration, options, lifetime management, delivery modes, and advanced features for Dapr.Messaging in .NET Learn more → Tutorial A seven-part tutorial for publishing and subscribing with the Dapr.Messaging .NET SDK, including unit and integration testing Learn more →

더 알아보기 (Learn more)