{"_id":"@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder","_rev":"3-53ebe2c72463dd1492858a7d981f6689","name":"@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder","dist-tags":{"latest":"3.0.0"},"versions":{"1.0.0":{"name":"@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder","version":"1.0.0","keywords":["rabbitmq","amqp","consumer","queue"],"license":"ISC","_id":"@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder@1.0.0","maintainers":[{"name":"eliseuvideira","email":"eliseuvideira1@gmail.com"}],"dist":{"shasum":"3e6ff8e44e97bbfd4a5f770d6259ad27c5844f9c","tarball":"https://registry.npmjs.org/@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder/-/rabbitmq-app-builder-1.0.0.tgz","fileCount":24,"integrity":"sha512-yPo8oz3MBEFsXtEhzRpaQOyvdHZ4C0dT760e9AFBByNhnsfTrmeQHWWWXcpoFnmUfVikur96a7lSy+KQxzkYtA==","signatures":[{"sig":"MEQCICDNwPm3Swto0uMIkVq7ze+t4hEm6z6OFYqR0Tt1pVYXAiA9xEJpjcv6LoAvSNtbZpnDH4f83OpB04ZAXsYFxk5ugQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15376},"main":"dist/index.js","_from":"file:55b89241-9bf2-4f24-b6e5-0d0936c86320-rabbitmq-app-builder-1.0.0.tgz","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"scripts":{"dev":"tsc --watch","build":"tsc"},"_npmUser":{"name":"eliseuvideira","email":"eliseuvideira1@gmail.com"},"_resolved":"/tmp/a829e0a488466a28fe7044badc5849f9/55b89241-9bf2-4f24-b6e5-0d0936c86320-rabbitmq-app-builder-1.0.0.tgz","_integrity":"sha512-yPo8oz3MBEFsXtEhzRpaQOyvdHZ4C0dT760e9AFBByNhnsfTrmeQHWWWXcpoFnmUfVikur96a7lSy+KQxzkYtA==","_npmVersion":"10.8.2","description":"RabbitMQ consumer application builder with graceful shutdown","directories":{},"_nodeVersion":"20.19.5","dependencies":{"amqplib":"^0.10.9"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.3","@types/node":"^24.10.0","@types/amqplib":"^0.10.8","@55b89241-9bf2-4f24-b6e5-0d0936c86320/logger":"0.2.0"},"peerDependencies":{"@55b89241-9bf2-4f24-b6e5-0d0936c86320/logger":"0.2.0"},"_npmOperationalInternal":{"tmp":"tmp/rabbitmq-app-builder_1.0.0_1762396608072_0.8657694227327801","host":"s3://npm-registry-packages-npm-production"}},"2.0.0":{"name":"@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder","version":"2.0.0","keywords":["rabbitmq","amqp","consumer","queue"],"license":"ISC","_id":"@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder@2.0.0","maintainers":[{"name":"eliseuvideira","email":"eliseuvideira1@gmail.com"}],"dist":{"shasum":"42cc8c3b3ffad647830395cabe7c7cae06e33cac","tarball":"https://registry.npmjs.org/@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder/-/rabbitmq-app-builder-2.0.0.tgz","fileCount":24,"integrity":"sha512-vu6bVWEXGj8VJssplOGv6M7wB6AO1t3BLCwITucttRuIyX/cAIySK4tMNYq/MZe/yCM9pjhvaYDUA6w3qyT/9w==","signatures":[{"sig":"MEUCIGyKrEz1k7uwyHTNfbWUO6WMhNVf3pTiw34Od9HORgqzAiEAyfWqnBnB/IDHiubJjI3GJR71cokbW6qXZJTbIO7gFJA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15401},"main":"dist/index.js","_from":"file:55b89241-9bf2-4f24-b6e5-0d0936c86320-rabbitmq-app-builder-2.0.0.tgz","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"scripts":{"dev":"tsc --watch","build":"tsc"},"_npmUser":{"name":"eliseuvideira","email":"eliseuvideira1@gmail.com"},"_resolved":"/tmp/a7b78a18424584924e3d10dddf56cae7/55b89241-9bf2-4f24-b6e5-0d0936c86320-rabbitmq-app-builder-2.0.0.tgz","_integrity":"sha512-vu6bVWEXGj8VJssplOGv6M7wB6AO1t3BLCwITucttRuIyX/cAIySK4tMNYq/MZe/yCM9pjhvaYDUA6w3qyT/9w==","_npmVersion":"10.8.2","description":"RabbitMQ consumer application builder with graceful shutdown","directories":{},"_nodeVersion":"20.19.5","dependencies":{"amqplib":"^0.10.9"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.3","@types/node":"^24.10.0","@types/amqplib":"^0.10.8","@55b89241-9bf2-4f24-b6e5-0d0936c86320/logger":"0.3.0"},"peerDependencies":{"@55b89241-9bf2-4f24-b6e5-0d0936c86320/logger":"0.3.0"},"_npmOperationalInternal":{"tmp":"tmp/rabbitmq-app-builder_2.0.0_1762397383323_0.16552492661757756","host":"s3://npm-registry-packages-npm-production"}},"3.0.0":{"name":"@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder","version":"3.0.0","description":"RabbitMQ consumer application builder with graceful shutdown","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"keywords":["rabbitmq","amqp","consumer","queue"],"license":"ISC","dependencies":{"amqplib":"^0.10.9"},"peerDependencies":{"@55b89241-9bf2-4f24-b6e5-0d0936c86320/logger":"0.4.0"},"devDependencies":{"@types/amqplib":"^0.10.8","@types/node":"^24.10.0","typescript":"^5.9.3","@55b89241-9bf2-4f24-b6e5-0d0936c86320/logger":"0.4.0"},"scripts":{"build":"tsc","dev":"tsc --watch"},"_id":"@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder@3.0.0","_integrity":"sha512-clJPFBLku6jzkh6czH2/H7RWJrg7xzSpmHiMFEY5/mpwO2p+3hCuR7OWJLpufnALLHMh71HkDf3lLWatxxQidg==","_resolved":"/tmp/6f3d8c2b1e0456a3b803eb92241f355a/55b89241-9bf2-4f24-b6e5-0d0936c86320-rabbitmq-app-builder-3.0.0.tgz","_from":"file:55b89241-9bf2-4f24-b6e5-0d0936c86320-rabbitmq-app-builder-3.0.0.tgz","_nodeVersion":"20.19.5","_npmVersion":"10.8.2","dist":{"integrity":"sha512-clJPFBLku6jzkh6czH2/H7RWJrg7xzSpmHiMFEY5/mpwO2p+3hCuR7OWJLpufnALLHMh71HkDf3lLWatxxQidg==","shasum":"d63777886f51ba001c5415c1cb66ebd976223189","tarball":"https://registry.npmjs.org/@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder/-/rabbitmq-app-builder-3.0.0.tgz","fileCount":24,"unpackedSize":15401,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCCain9fChdo9WObVuBXqeGADcysMKXQ+KyVrlZhamexQIgFRxbQ0swNSkUT5DmGnyIWCxWCeyvWKBnjoFEGbjgPqQ="}]},"_npmUser":{"name":"eliseuvideira","email":"eliseuvideira1@gmail.com"},"directories":{},"maintainers":[{"name":"eliseuvideira","email":"eliseuvideira1@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/rabbitmq-app-builder_3.0.0_1762430233935_0.4969124381541228"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-06T02:36:47.921Z","modified":"2025-11-06T11:57:14.342Z","1.0.0":"2025-11-06T02:36:48.277Z","2.0.0":"2025-11-06T02:49:43.530Z","3.0.0":"2025-11-06T11:57:14.109Z"},"license":"ISC","keywords":["rabbitmq","amqp","consumer","queue"],"description":"RabbitMQ consumer application builder with graceful shutdown","maintainers":[{"name":"eliseuvideira","email":"eliseuvideira1@gmail.com"}],"readme":"# @55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder\n\nRabbitMQ consumer application builder with automatic connection management and graceful shutdown.\n\n## Features\n\n- Declarative queue/handler definitions\n- Automatic connection and channel management\n- Graceful shutdown (waits for in-flight messages)\n- Generic over Context type\n- Supports RPC pattern with replyTo\n- Automatic message parsing and error handling\n- Correlation ID support\n\n## Installation\n\n```bash\nnpm install @55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder @55b89241-9bf2-4f24-b6e5-0d0936c86320/logger\n# or\npnpm add @55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder @55b89241-9bf2-4f24-b6e5-0d0936c86320/logger\n```\n\n## Usage\n\n### Basic Example\n\n```typescript\nimport { AppBuilder } from \"@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder\";\nimport { LoggerBuilder } from \"@55b89241-9bf2-4f24-b6e5-0d0936c86320/logger\";\nimport type { Config, MessageHandler } from \"@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder\";\n\n// Define your config type\nconst config: Config = {\n  RABBITMQ_URL: process.env.RABBITMQ_URL || \"amqp://localhost\",\n};\n\n// Create handlers\nconst processOrderHandler: MessageHandler = async (content, ctx) => {\n  ctx.logger.info(\"Processing order\", { content });\n\n  // Your business logic here\n  const result = { orderId: content.id, status: \"processed\" };\n\n  return result;\n};\n\nconst sendEmailHandler: MessageHandler = async (content, ctx) => {\n  ctx.logger.info(\"Sending email\", { content });\n\n  // Your business logic here\n\n  return { sent: true };\n};\n\n// Build the app\nconst builder = AppBuilder((config) => [\n  { queue: \"orders\", handler: processOrderHandler },\n  { queue: \"emails\", handler: sendEmailHandler },\n]);\n\nconst logger = await LoggerBuilder.build(process.env);\nconst app = await builder.build(config, logger);\n\n// Run the app\nawait app.run();\n\n// Graceful shutdown\nprocess.on(\"SIGINT\", async () => {\n  await app.stop();\n  process.exit(0);\n});\n```\n\n### With Custom Context\n\n```typescript\nimport type { Logger } from \"@55b89241-9bf2-4f24-b6e5-0d0936c86320/logger\";\n\n// Define custom context\ntype MyContext = {\n  logger: Logger;\n  db: DatabaseConnection;\n  cache: RedisClient;\n};\n\nconst handler: MessageHandler<MyContext> = async (content, ctx) => {\n  // ctx has type MyContext and includes logger, db, cache\n  const user = await ctx.db.users.findOne({ id: content.userId });\n  ctx.logger.info(\"Found user\", { user });\n  return user;\n};\n\n// Note: The AppBuilder is generic but the context type is enforced in the handler\n// You'll need to cast the context in the handler or manage context creation yourself\n```\n\n### Error Handling\n\nErrors are automatically caught and logged. If the message has a `replyTo` property, an error reply is sent back:\n\n```typescript\nconst handler: MessageHandler = async (content, ctx) => {\n  if (!content.email) {\n    throw new Error(\"Email is required\");\n  }\n\n  // This error will be caught, logged, and sent as a reply if replyTo is set\n  // The message will be nack'd without requeue\n};\n```\n\n### RPC Pattern\n\nThe builder automatically supports RPC:\n\n```typescript\n// Consumer side (already handled by AppBuilder)\nconst handler: MessageHandler = async (content, ctx) => {\n  return { result: \"computed value\" };\n};\n\n// If the message has correlationId and replyTo, the result\n// will be sent back automatically\n```\n\n## API\n\n### AppBuilder\n\n```typescript\nAppBuilder<Context>(\n  define: (config: Config) => Array<{\n    queue: string;\n    handler: MessageHandler<Context>;\n  }>\n)\n```\n\nReturns a builder with a `build` method.\n\n### builder.build(config, logger)\n\n```typescript\nbuild(config: Config, logger: Logger): Promise<App>\n```\n\nCreates the app with all queue consumers ready.\n\n### App\n\n```typescript\ntype App = {\n  run: () => Promise<void>;\n  stop: () => Promise<void>;\n};\n```\n\n- `run()`: Start consuming messages from all queues\n- `stop()`: Gracefully shutdown (cancel consumers, wait for in-flight messages, close connections)\n\n### MessageHandler\n\n```typescript\ntype MessageHandler<Context extends { logger: Logger }> = (\n  content: unknown,\n  ctx: Context\n) => Promise<unknown>;\n```\n\n## Type Exports\n\n```typescript\nimport type {\n  App,\n  Config,\n  MessageHandler,\n  SuccessReply,\n  ErrorReply,\n} from \"@55b89241-9bf2-4f24-b6e5-0d0936c86320/rabbitmq-app-builder\";\n```\n\n## How It Works\n\n1. AppBuilder takes a function that returns queue/handler definitions\n2. On `build()`, it connects to RabbitMQ and creates channels for each queue\n3. Each handler is wrapped with message handling logic (parsing, logging, error handling)\n4. On `run()`, it starts consuming messages\n5. On `stop()`, it:\n   - Sets shutdown flag (new messages are requeued)\n   - Cancels all consumers\n   - Waits for in-flight messages to complete\n   - Closes all channels and connection\n","readmeFilename":"README.md"}