* docs: migrate ui docs to docs universe * created yarn workspace * added eslint and tsconfig configurations * fix eslint configurations * fixed eslint configurations * shared tailwind configurations * added shared ui package * added more shared components * migrating more components * made details components shared * move InlineCode component * moved InputText * moved Loading component * Moved Modal component * moved Select components * Moved Tooltip component * moved Search components * moved ColorMode provider * Moved Notification components and providers * used icons package * use UI colors in api-reference * moved Navbar component * used Navbar and Search in UI docs * added Feedback to UI docs * general enhancements * fix color mode * added copy colors file from ui-preset * added features and enhancements to UI docs * move Sidebar component and provider * general fixes and preparations for deployment * update docusaurus version * adjusted versions * fix output directory * remove rootDirectory property * fix yarn.lock * moved code component * added vale for all docs MD and MDX * fix tests * fix vale error * fix deployment errors * change ignore commands * add output directory * fix docs test * general fixes * content fixes * fix announcement script * added changeset * fix vale checks * added nofilter option * fix vale error
46 lines
2.1 KiB
Plaintext
46 lines
2.1 KiB
Plaintext
---
|
||
description: 'Learn what subscribers are in Medusa. Subscribers are used to listen to triggered events to perform an action.'
|
||
---
|
||
|
||
import DocCard from '@theme/DocCard';
|
||
import Icons from '@theme/Icon';
|
||
|
||
# Subscribers
|
||
|
||
In this document, you'll learn what Subscribers are in Medusa.
|
||
|
||
## What are Subscribers
|
||
|
||
Subscribers register handlers for an events and allows you to perform an action when that event occurs. For example, if you want to send your customer an email when they place an order, then you can listen to the `order.placed` event and send the email when the event is emitted.
|
||
|
||
Natively in Medusa there are subscribers to handle different events. However, you can also create your own custom subscribers.
|
||
|
||
Custom subscribers are TypeScript or JavaScript files in your project's `src/subscribers` directory. Files here should export classes, which will be treated as subscribers by Medusa. By convention, the class name should end with `Subscriber` and the file name should be the camel-case version of the class name without `Subscriber`. For example, the `WelcomeSubscriber` class is in the file `src/subscribers/welcome.ts`.
|
||
|
||
Whenever an event is emitted, the subscriber’s registered handler method is executed. The handler method receives as a parameter an object that holds data related to the event. For example, if an order is placed the `order.placed` event will be emitted and all the handlers will receive the order id in the parameter object.
|
||
|
||
### Example Use Cases
|
||
|
||
Subscribers are useful in many use cases, including:
|
||
|
||
- Send a confirmation email to the customer when they place an order by subscribing to the `order.placed` event.
|
||
- Automatically assign new customers to a customer group by subscribing to the `customer.created`.
|
||
- Handle custom events that you emit
|
||
|
||
---
|
||
|
||
## Custom Development
|
||
|
||
Developers can create custom subscribers in the Medusa backend, a plugin, or in a module.
|
||
|
||
<DocCard item={{
|
||
type: 'link',
|
||
href: '/development/events/create-subscriber',
|
||
label: 'Create a Subscriber',
|
||
customProps: {
|
||
icon: Icons['academic-cap-solid'],
|
||
description: 'Learn how to create a subscriber in Medusa.'
|
||
}
|
||
}}
|
||
/>
|