{"id":17469766,"url":"https://github.com/mshick/hapi-rabbitmq","last_synced_at":"2025-09-20T21:32:46.697Z","repository":{"id":57261035,"uuid":"84758282","full_name":"mshick/hapi-rabbitmq","owner":"mshick","description":"A HAPI server plugin exposing RabbitMQ-backed PubSub and task queue pattern methods from librabbitmq.","archived":false,"fork":false,"pushed_at":"2018-07-13T14:45:19.000Z","size":185,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-30T21:22:05.528Z","etag":null,"topics":["amqp","hapi","pubsub","rabbitmq","task-queue"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mshick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-12T21:21:32.000Z","updated_at":"2024-04-13T13:00:31.000Z","dependencies_parsed_at":"2022-08-31T16:21:14.747Z","dependency_job_id":null,"html_url":"https://github.com/mshick/hapi-rabbitmq","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshick%2Fhapi-rabbitmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshick%2Fhapi-rabbitmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshick%2Fhapi-rabbitmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshick%2Fhapi-rabbitmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mshick","download_url":"https://codeload.github.com/mshick/hapi-rabbitmq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233690478,"owners_count":18714782,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amqp","hapi","pubsub","rabbitmq","task-queue"],"created_at":"2024-10-18T15:43:43.663Z","updated_at":"2025-09-20T21:32:41.399Z","avatar_url":"https://github.com/mshick.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"hapi-rabbitmq [![Build Status](https://travis-ci.org/mshick/hapi-rabbitmq.svg?branch=master)](https://travis-ci.org/mshick/hapi-rabbitmq) [![npm version](https://badge.fury.io/js/hapi-rabbitmq.svg)](https://badge.fury.io/js/hapi-rabbitmq)\n==============\n\nA HAPI server plugin exposing RabbitMQ-backed PubSub and task queue pattern methods from [librabbitmq](https://github.com/mshick/librabbitmq/).\n\nConfiguration\n-------------\n\nThe only required config is the url for your RabbitMQ server:\n\n```js\nserver.register({\n  register: require('hapi-rabbitmq'),\n  options: {\n    url: 'amqp://localhost'\n  }\n});\n```\n\nThis plugin sets two notable defaults, intended to give good results on a HAPI server, where you are probably registering many decoupled plugins, and probably might not know which first set up your RabbitMQ connection.\n\n```js\n{\n  preserveChannels: true,\n  connection: {\n    useExisting: true\n  }\n}\n```\n\nThere are many more configuration options which are passed through to librabbitmq. [Read more about them](https://github.com/mshick/librabbitmq#configuration).\n\nUsage\n-----\n\nGenerally speaking, you only need to create a connection once, and that will be reused for all of your channel creation. You do have the option of creating multiple connections and passing those to the methods that create channels, if you need greater control.\n\n### PubSub\n\n```js\n\n// Register plugin... start server\n\nconst {rabbitmq} = server.methods;\n\nconst subscriber = function (message) {\n  return new Promise(() =\u003e {\n    console.log('Message: ', message.payload);\n  });\n};\n\nrabbitmq.createConnection()\n  .then(() =\u003e {\n    return rabbitmq.addSubscriber({\n      exchange: 'pubsub',\n      subscriber\n    });\n  })\n  .then(() =\u003e next())\n  .catch(next);\n\n\nserver.route({\n  method: 'POST',\n  path: '/publish',\n  handler(request, reply) {\n    rabbitmq.publishMessage({\n      exchange: 'pubsub',\n      topic: 'request',\n      payload: request.payload\n    })\n    .then(() =\u003e reply('ok'))\n    .catch(reply);\n  }\n});\n```\n\n### Task queue\n\n```js\n\n// Register plugin... start server\n\nconst {rabbitmq} = server.plugins;\nconst {ACK} = server.plugins['hapi-rabbitmq'].constants;\n\nconst worker = function (task) {\n  return new Promise(resolve =\u003e {\n    setTimeout(() =\u003e {\n      console.log(task.payload);\n      resolve(ACK);\n    }, 1000);\n  });\n};\n\nrabbitmq.createConnection()\n  .then(() =\u003e {\n    return rabbitmq.addWorker({\n      queue: 'work',\n      worker\n    });\n  })\n  .then(() =\u003e next())\n  .catch(next);\n\nserver.route({\n  method: 'POST',\n  path: '/work',\n  handler(request, reply) {\n    rabbitmq\n      .pushTask({\n        queue: 'work',\n        type: 'foo',\n        payload: request.payload\n      })\n      .then(() =\u003e reply('ok'))\n      .catch(reply);\n  }\n});\n```\n\nRequirements\n------------\n\n*   node.js \u003e= 6.0\n*   RabbitMQ 3.6.11 (only version tested)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmshick%2Fhapi-rabbitmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmshick%2Fhapi-rabbitmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmshick%2Fhapi-rabbitmq/lists"}