Skip to content

Latest commit

 

History

History
38 lines (24 loc) · 1.22 KB

publish-handle-event.md

File metadata and controls

38 lines (24 loc) · 1.22 KB
title summary component reviewed related
Publish and Handle an Event
How to define, publish, and handle events
Core
2024-01-12
samples/pubsub
tutorials/nservicebus-step-by-step
nservicebus/messaging/messages-events-commands

Event messages need to either implement IEvent or match a custom DefiningEventsAs convention. See the message design documentation for more details.

Handling an event

In order to handle an event, implement the IHandleMessages<T> interface in any handler or saga class, where T is the specific event type.

Publishing an event

Call the Publish method to publish an event.

There are a few common scenarios for publishing events. Events might be published:

  • from a handler, when processing another message.

snippet: publishFromHandler

  • from a saga handler, when processing another message.

snippet: publishFromSaga

  • at endpoint startup

snippet: publishAtStartup

Composing events

In order to support advanced composition scenarios, events can be defined as interfaces. See the Messages as Interfaces for more details.