{"_id":"@artie-owlet/cabbit","_rev":"1-b21b690ebcbf7169e5cce7dc48995fbb","name":"@artie-owlet/cabbit","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@artie-owlet/cabbit","version":"1.0.0","description":"Package for easy consuming messages from RabbitMQ","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","clean":"rm -rf dist/","lint":"eslint --cache --ext .js,.jsx,.ts,.tsx src/ test/","test":"mocha -r ts-node/register test/*.ts","coverage":"nyc npm run test","doc":"typedoc"},"license":"MIT","dependencies":{"@artie-owlet/amqplib-wrapper":"^2.0.0"},"devDependencies":{"@istanbuljs/nyc-config-typescript":"^1.0.1","@types/amqplib":"^0.8.2","@types/chai":"^4.2.22","@types/chai-as-promised":"^7.1.4","@types/mocha":"^9.0.0","@types/node":"^16.11.6","@types/qs":"^6.9.7","@typescript-eslint/eslint-plugin":"^5.2.0","@typescript-eslint/parser":"^5.2.0","chai":"^4.3.4","chai-as-promised":"^7.1.1","eslint":"^8.1.0","mocha":"^9.1.3","nyc":"^15.1.0","qs":"^6.10.1","ts-node":"^10.4.0","typedoc":"^0.22.13","typescript":"^4.4.4"},"repository":{"type":"git","url":"git+https://github.com/artie-owlet/cabbit.git"},"gitHead":"32fe1a8878039a9adc651fa6b339058597ec14fe","bugs":{"url":"https://github.com/artie-owlet/cabbit/issues"},"homepage":"https://github.com/artie-owlet/cabbit#readme","_id":"@artie-owlet/cabbit@1.0.0","_nodeVersion":"16.14.0","_npmVersion":"8.3.1","dist":{"integrity":"sha512-sxJNG2Dde+lr+UxQd9b1akmubRdrR5fvKHUJ9GGc58f2JaUNC4HOzKQ2imihnzux5XSRZGDxXFe+8vIFnrcJHA==","shasum":"a526f06991bec66d40c65263158d1bd08930c6aa","tarball":"https://registry.npmjs.org/@artie-owlet/cabbit/-/cabbit-1.0.0.tgz","fileCount":24,"unpackedSize":82186,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiOjcDACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrS6A//Qz4+8DwsoReYU/2NIoGSBhUnK6l8xiz43uHkI9F87Qc4N4Aq\r\n6N8oXPNZTY8anJPQAm866f6GL/k1dSCbgDvkdTrGFqGl8M3LySpHm5Bvf70p\r\nW767CR/gjTPQWYZ12UOHi2q5JpZbFSoa3jK80Iqw33VSbDlzi0BoRJqUWYLK\r\n9j3c8bVc3+P3N5ZpcSCdbEZfOszY58ZRUTkmgho/MY8EnBdmymDp+BwVrvwi\r\nZR+/HSp34qP5VBOYkaZ41BGoUG2FFOfvivVppkRSx27BdUzJFlUCwZ+In0lu\r\nwX8exObWvBOguCALkCp4YW1OE7y/F2IMJbbHNVeHWy+oyv64RDopC0SbdneW\r\nJsp8ndnIJXQJda//407/5BxTAwFtG8qYZH/rwb07A94mTICgQTzwH+SWCswB\r\n4gsrYNrQUV7CfqWeQWXkNY1YIe4WmtU7IEvYIbCBd+haEf6Aj1y7ltV6TvgM\r\nGx30+ZXv/eas4wCyYiowhEY3Tsh+jkVqjhgnydN4h4ccscskmTcGEpEY/MlN\r\n9bJdX3374udYcl0rFP3C/25e5dh0k4UJcYenvqUobgROIH9XYheJYk5VmvT1\r\nNWvkQdbIqDE9s1SCa9G5be4CnjC6V8kWABvbuV9KeBeNTtm0q9hvRPgK+jNW\r\n4vrySCf/T1669GS299/m7LDdMDkFG+4Vuw8=\r\n=HAUU\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDTiSFx8kf+CHu1PGyX2piyLdvWg7BDh2A/3Rk7Q1EFvAiEAgmEk/tIzid9MjCGJJ8TugWCMhrZZJGni09tFMac12/E="}]},"_npmUser":{"name":"artie-owlet","email":"artie-owlet@protonmail.com"},"directories":{},"maintainers":[{"name":"artie-owlet","email":"artie-owlet@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cabbit_1.0.0_1647982339637_0.8918657752786077"},"_hasShrinkwrap":false}},"time":{"created":"2022-03-22T20:52:19.565Z","1.0.0":"2022-03-22T20:52:19.803Z","modified":"2022-04-04T15:38:34.976Z"},"maintainers":[{"name":"artie-owlet","email":"artie-owlet@protonmail.com"}],"description":"Package for easy consuming messages from RabbitMQ","homepage":"https://github.com/artie-owlet/cabbit#readme","repository":{"type":"git","url":"git+https://github.com/artie-owlet/cabbit.git"},"bugs":{"url":"https://github.com/artie-owlet/cabbit/issues"},"license":"MIT","readme":"# cabbit\n![CI](https://github.com/artie-owlet/cabbit/actions/workflows/ci.yaml/badge.svg)\n![Coverage](https://github.com/artie-owlet/cabbit/actions/workflows/coverage.yaml/badge.svg)\n![Lint](https://github.com/artie-owlet/cabbit/actions/workflows/lint.yaml/badge.svg)\n\nPackage for easy consuming messages from RabbitMQ.\n\n---\n\n## Install\n\n```bash\nnpm install @artie-owlet/cabbit\n```\n\n## Usage\n\n### Get started\n\nYou can create cabbit with its own connection:\n\n```ts\nimport { Cabbit } from '@artie-owlet/cabbit';\n// using connection URL\nconst cabbit1 = new Cabbit('amqp://user:pwd@example.com:5672/');\n// using options\nconst cabbit2 = new Cabbit({\n    hostname: 'example.com',\n    port: 5672,\n    username: 'user',\n    password: 'pwd',\n    vhost: '/',\n})\n```\n\nOr you can create your own connection (using the [ConnectionWrapper](https://github.com/artie-owlet/amqplib-wrapper)) and pass it to Cabbit constructor (e.g. you also want to publish messages):\n\n```ts\nimport { ConnectionWrapper } from '@artie-owlet/amqplib-wrapper';\nimport { Cabbit } from '@artie-owlet/cabbit';\n\nconst connWrap = new ConnectionWrapper('amqp://user:pwd@example.com:5672/?reconnectTimeout=1000');\n// cabbit for consuming messages\nconst cabbit = new Cabbit(connWrap);\n// another channel for publishing messages\nconst chan = await chanWrap.getChannel();\n```\n\n### Consuming from named queue\n\n```mermaid\ngraph LR\n    pub{{Pub}} --> queue[test_queue] --> sub{{Sub}}\n```\n\n```ts\ncabbit.queue('test_queue', (msg) => {\n    if (msg.body === undefined) {\n        console.error(msg.parseError);\n    } else {\n        console.log(msg.body);\n    }\n    msg.ack();\n});\n```\n\n**NOTE:** Cabbit trying to decode and parse messages according to their encoding and MIME-type. If an error occurs the `body` will be `undefined`. Usually you should check it.\n\n### Simple subcribing to exchange\n\n```mermaid\ngraph LR\n    pub{{Pub}} --> ex((D test_ex)) -- key --> queue[test_queue] --> sub{{Sub}}\n```\n\nIn such simple cases, Cabbit represents the subscription as a consumption from the exchange through the (named) queue:\n\n```ts\ncabbit.direct('test_ex').consume('test_queue', (msg) => {\n    // handle message\n    msg.ack();\n}, 'key');\n```\n\n### Temporary queue\n\nTemporary queue - is a server-named queue which should be removed after the client disconnects. By default Cabbit consumes from a temporary queue with `noAck=true`.\n\n```mermaid\ngraph LR\n    pub{{Pub}} --> ex((D test_ex)) -- key --> queue[amq.gen-...] --> sub{{Sub}}\n```\n\n```ts\ncabbit.direct('test_ex').consume((msg) => {\n    // handle message\n    // DON'T call msg.ack()\n}, 'key');\n```\n\n### Complex example\n\n```mermaid\ngraph LR\n    pub{{Pub}}\n    sub{{Sub}}\n    ex1((D log_ex))\n    ex2((H error_ex))\n    queue1[all_logs_q]\n    queue2[test_err_q]\n    pub --> ex1\n    ex1 -- info --> queue1\n    ex1 -- warn --> queue1\n    ex1 -- error --> queue1\n    queue1 --> sub\n    ex1 -- error --> ex2 -->queue2 -->sub\n```\n\n```ts\nconst logEx = cabbit.direct('log_ex');\n\nlogEx.consume('all_logs_q', (msg) => {\n    switch (msg.fields.routingKey) {\n        // handle message according to its routing key\n    }\n    msg.ack();\n}, ['info', 'warn', 'error']); // you can pass a list of routing keys\n\nlogEx.headers('error_ex').consume('test_err_q', (msg) => {\n    // handle message\n    msg.ack();\n}, {\n    'x-match': 'all',\n    app: 'test',\n});\n```\n\n### Subscribing to multiple exchanges\n\n```mermaid\ngraph LR\n    pub1{{Pub 1}} --> ex1((D ex1)) -- key --> queue[test_queue] --> sub{{Sub}}\n    pub2{{Pub 2}} --> ex2((F ex2)) --> queue\n```\n\n```ts\ncabbit.queue('test_queue', (msg) => {\n    // handle message\n    msg.ack();\n}).subscribe(cabbit.direct('ex1'), 'key').subscribe(cabbit.fanout('ex2'));\n```\n\n## API\n\nSee https://artie-owlet.github.io/cabbit/\n","readmeFilename":"README.md"}