docs: add documentation for Locking Module (#11824)

* add locking docs

* fix main navbar

* added implementation example links

* generate refs

* update architecture

* fix vale error
This commit is contained in:
Shahed Nasser
2025-03-13 12:20:24 +02:00
committed by GitHub
parent 5cf0bf4d93
commit 28b0d08591
94 changed files with 15932 additions and 10857 deletions
@@ -1,10 +1,10 @@
export const metadata = {
title: `Local Event Bus Module`,
title: `Local Event Module`,
}
# {metadata.title}
The Local Event Bus Module uses Node EventEmitter to implement Medusa's pub/sub events system. The Node EventEmitter is limited to a single process environment.
The Local Event Module uses Node EventEmitter to implement Medusa's pub/sub events system. The Node EventEmitter is limited to a single process environment.
This module is useful for development and testing, but its not recommended to be used in production.
@@ -12,11 +12,11 @@ For production, its recommended to use modules like [Redis Event Bus Module](
---
## Register the Local Event Bus Module
## Register the Local Event Module
<Note>
The Local Event Bus Module is registered by default in your application.
The Local Event Module is registered by default in your application.
</Note>
@@ -1,22 +1,80 @@
import { CardList } from "docs-ui"
export const metadata = {
title: `Event Modules`,
title: `Event Module`,
}
# {metadata.title}
In this document, you'll learn what an Event Module is and how to use it in your Medusa application.
## What is an Event Module?
An Event Module implements the underlying publish/subscribe system that handles queueing events, emitting them, and executing their subscribers.
This makes the event architecture customizable, as you can either choose one of Medusas event modules or create your own.
<Note>
Learn more about Medusa's event systems in the [Events and Subscribers documentation](!docs!/learn/fundamentals/events-and-subscribers).
</Note>
### Default Event Module
By default, Medusa uses the [Local Event Module](./local/page.mdx). This module uses Nodes EventEmitter to implement the publish/subscribe system. While this is suitable for development, it's recommended to use other Event Modules, such as the [Redis Event Module](./redis/page.mdx), for production. You can also [Create an Event Module](./create/page.mdx).
---
## How to Use the Event Module?
You can use the registered Event Module as part of the [workflows](!docs!/learn/fundamentals/workflows) you build for your custom features. A workflow is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.
Medusa provides the helper step [emitEventStep](/references/helper-steps/emitEventStep) that you can use in your workflow. You can also resolve the Event Module's service in a step of your workflow and use its methods to emit events.
For example:
```ts
import { Modules } from "@medusajs/framework/utils"
import {
createStep,
createWorkflow,
} from "@medusajs/framework/workflows-sdk"
const step1 = createStep(
"step-1",
async ({}, { container }) => {
const eventModuleService = container.resolve(
Modules.EVENT
)
await eventModuleService.emit({
name: "custom.event",
data: {
id: "123",
// other data payload
},
})
}
)
export const workflow = createWorkflow(
"workflow-1",
() => {
step1()
}
)
```
In the example above, you create a workflow that has a step. In the step, you resolve the service of the Event Module from the [Medusa container](!docs!/learn/fundamentals/medusa-container).
Then, you use the `emit` method of the Event Module to emit an event with the name `"custom.event"` and the data payload `{ id: "123" }`.
---
## List of Event Modules
By default, Medusa uses the Local Event Module. This module uses Nodes EventEmitter to implement the publish/subscribe system.
This is useful for development. However, for production, its highly recommended to use other Event Modules, Redis Event Module.
Medusa provides the following Event Modules. You can use one of them, or [Create an Event Module](./create/page.mdx).
<CardList
items={[
@@ -38,9 +96,3 @@ This is useful for development. However, for production, its highly recommend
}
]}
/>
---
## Create a Event Module
To create an event module, refer to [this guide](./create/page.mdx).
@@ -1,12 +1,12 @@
import { Table, Prerequisites } from "docs-ui"
export const metadata = {
title: `Redis Event Bus Module`,
title: `Redis Event Module`,
}
# {metadata.title}
The Redis Event Bus Module uses Redis to implement Medusa's pub/sub events system.
The Redis Event Module uses Redis to implement Medusa's pub/sub events system.
It's powered by BullMQ and `io-redis`. BullMQ is responsible for the message queue and worker, and `io-redis` is the underlying Redis client that BullMQ connects to for events storage.
@@ -14,7 +14,7 @@ In production, it's recommended to use this module.
---
## Register the Redis Events Bus Module
## Register the Redis Event Module
<Prerequisites items={[
{
@@ -55,7 +55,7 @@ Make sure to add the following environment variables:
EVENTS_REDIS_URL=<YOUR_REDIS_URL>
```
### Redis Event Bus Module Options
### Redis Event Module Options
<Table>
<Table.Header>