www/apps/resources/app/troubleshooting/subscribers/not-working/page.mdx
import NotRunningWorkerMode from "../../_sections/subscribers/not_running_workermode.mdx" import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = {
title: Subscribers Not Working,
}
This troubleshooting guide helps you troubleshoot issues when subscribers in your Medusa application are not running.
Make sure that the event you're trying to listen to is actually being emitted. You can do this by adding a console log or using a debugger in the part of your code where the event is emitted.
For example:
<CodeTabs group="emit_event"> <CodeTab label="In a Workflow" value="workflow"> ```ts title="src/workflows/your-workflow.ts" import { createWorkflow, transform } from "@medusajs/framework/workflows-sdk" import { emitEventStep, } from "@medusajs/medusa/core-flows"const helloWorldWorkflow = createWorkflow( "hello-world", () => { // ...
emitEventStep({
eventName: "custom.created",
data: {
id: "123",
// other data payload
},
})
transform({}, () => {
// For debugging purposes
console.log("Event emitted: custom.created")
})
} )
</CodeTab>
<CodeTab label="Using Event Module's Service" value="service">
```ts
eventBusService_.emit({
name: "custom.event",
data: {
id: "123",
// other data payload
},
})
console.log("Event emitted: custom.event")
If the event is not being emitted, check the logic in your code to ensure that the event emission is correctly implemented.
Make sure that your subscriber is correctly set up to listen to the event you're emitting. Check the following:
src/subscribers directory.import { SubscriberArgs, type SubscriberConfig } from "@medusajs/framework"
export default async function orderPlacedHandler({
event: { data },
container,
}: SubscriberArgs<{ id: string }>) {
const logger = container.resolve("logger")
logger.info("Sending confirmation email...")
// ...
}
export const config: SubscriberConfig = {
event: `order.placed`, // Confirm this name is correct
}
If your subscriber is set up correctly, you'll see the following log in the terminal when the event is emitted:
info: Processing order.placed which has 1 subscribers