Custom subscribers
Last updated
Last updated
Subscribers handle events emitted in the Medusa application.
Learn more about Subscribers in .
The subscriber is created in a TypeScript or JavaScript file under the src/subscribers
directory.
For example, create the file src/subscribers/product-created.ts
with the following content:
A subscriber file must export:
The subscriber function that is an asynchronous function executed whenever the associated event is triggered.
A configuration object defining the event this subscriber is listening to.
A subscriber receives an object having the following properties:
event
: An object holding the event's details. It has a data
property, which is the event's data payload.
container
: The Medusa container. Use it to resolve modules' main services and other registered resources.