{"_id":"@del-internet/support-broker","name":"@del-internet/support-broker","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@del-internet/support-broker","version":"1.0.0","description":"TypeScript package to handle pub/sub events based on RabbitMQ","main":"dist/index.js","private":false,"publishConfig":{"access":"public"},"engines":{"node":">= 18.0.0"},"scripts":{"build":"tsc --declaration"},"repository":{"type":"git","url":"https://gitlab.delinternet.com/zareismail/support-broker.git"},"author":{"name":"Ismail Zare","email":"zarehesmaiel@gmail.com"},"license":"MIT","bugs":{"url":"https://gitlab.delinternet.com/zareismail/support-broker/-/issues"},"homepage":"https://gitlab.delinternet.com/zareismail/support-broker/-/blob/main/README.md","keywords":["broker","RabbitMQ","Delinternet"],"dependencies":{"@steads/manager":"^1.1","amqplib":"^0.10"},"devDependencies":{"@types/node":"^20.9","prettier":"^3.1","@types/amqplib":"^0.10","typescript":"^5.2"},"_id":"@del-internet/support-broker@1.0.0","gitHead":"329a95bb7c9e7c476a693ee4b141e9590c3aa07b","types":"./dist/index.d.ts","_nodeVersion":"18.17.1","_npmVersion":"10.2.5","dist":{"integrity":"sha512-vVGzEF2KXezxu6Ep8Npu/WPHXxfeLmbm3Ty/FH+e72bRJ73ZMmF2S84MvEgM9vg0GoMBElCwEj3BPGuNXDzt3A==","shasum":"1082ea5e1fdc439378dbd13449c4af247358e4dd","tarball":"https://registry.npmjs.org/@del-internet/support-broker/-/support-broker-1.0.0.tgz","fileCount":12,"unpackedSize":11340,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCrW790nTGu8X1XggOGyci/JxuxJzrXkQhFnvZLLEgUuwIhAJAefHoekUWrXuW4uq7rl8xIECMc0V0ub5h7sbjY2jVQ"}]},"_npmUser":{"name":"zareismail","email":"zarehesmaiel@gmail.com"},"directories":{},"maintainers":[{"name":"zareismail","email":"zarehesmaiel@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/support-broker_1.0.0_1704357875827_0.45656227222455703"},"_hasShrinkwrap":false}},"time":{"created":"2024-01-04T08:44:35.765Z","1.0.0":"2024-01-04T08:44:36.021Z","modified":"2024-01-04T08:44:36.322Z"},"maintainers":[{"name":"zareismail","email":"zarehesmaiel@gmail.com"}],"description":"TypeScript package to handle pub/sub events based on RabbitMQ","homepage":"https://gitlab.delinternet.com/zareismail/support-broker/-/blob/main/README.md","keywords":["broker","RabbitMQ","Delinternet"],"repository":{"type":"git","url":"https://gitlab.delinternet.com/zareismail/support-broker.git"},"author":{"name":"Ismail Zare","email":"zarehesmaiel@gmail.com"},"bugs":{"url":"https://gitlab.delinternet.com/zareismail/support-broker/-/issues"},"license":"MIT","readme":"# support-event\n\n# Getting Start\n\nThis package implemented to distribute huge task to some workers by RabbitMQ broker.\nFor example, manipulate the image uploaded to server wast many server resources and time, on this situation we could create a task\nand distribute the image manipulation into other services and servers, and when the task finished we will have the new images without\nwaiting for manipulation.\n\nThis package has two main features:\n\n1. [Tasks](#tasks)\n2. [Workers](#workers)\n\n# Initializing\n\n```\nimport { Broker } from '@del-internet/support-broker';\n\nconst broker = new Broker({\n  hostname: 'hostname...',\n  username: 'username...',\n  password: 'password...',\n});\n```\n\n# Tasks\n\nThe main idea behind Task Queues is to avoid doing a resource-intensive task immediately and having to wait for it to complete. Instead we schedule the task to be done later. We encapsulate a task as a message and send it to a queue. A worker process running in the background will pop the tasks and eventually execute the job.\n\nto create a task you have to create a class like so:\n\n```\nimport { Task } from '@del-internet/support-broker';\n\nclass ResizeImage extends Task {\n  payload(): Record<string, unknown> {\n    return {\n      id: ....,\n    };\n  }\n}\n```\n\neach task has a `payload` method that allow you pass the task requirements.\n\n## Distribute a task\n\nAfter creating a task you should register it by the broker:\n\n```\nawait broker.distribute(new ResizeImage());\n```\n\n# Workers\n\nWhen you send a task to the broker service, the broker service waiting for workers to handle the task. each worker receive a task data, and doing desired required on it. for example: \"ResizeImageWorker\" could resize the image by url or id received from the task.\n\nto create a worker you have to create a class like so:\n\n```\nimport { Worker } from '@del-internet/support-broker';\n\nclass ResizeImageWorker extends Worker {\n  async handle({ payload: { id } }: Record<string, unknown>): Promise<void> {\n    // do resizing operation\n  }\n}\n```\n\neach worker has a `handle` method that receive a object contained task \"payload\". you have to do the task operations on this method.\n\n## Registering a worker task\n\nAfter creating a worker you should register it by the broker:\n\n```\nawait broker.register(new ResizeImageWorker());\n```\n","readmeFilename":"README.md"}