{"id":19020223,"url":"https://github.com/trailsjs/trailpack-pubsub","last_synced_at":"2026-04-28T07:30:19.318Z","repository":{"id":57378898,"uuid":"71553941","full_name":"trailsjs/trailpack-pubsub","owner":"trailsjs","description":"Redis Pub/Sub implementation for Trails.js app","archived":false,"fork":false,"pushed_at":"2016-12-19T15:42:16.000Z","size":17,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T15:35:38.319Z","etag":null,"topics":["pubsub","trailpack","trails"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trailsjs.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":"2016-10-21T10:04:00.000Z","updated_at":"2016-11-14T08:46:41.000Z","dependencies_parsed_at":"2022-09-02T20:21:49.101Z","dependency_job_id":null,"html_url":"https://github.com/trailsjs/trailpack-pubsub","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrailpack-pubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrailpack-pubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrailpack-pubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailsjs%2Ftrailpack-pubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trailsjs","download_url":"https://codeload.github.com/trailsjs/trailpack-pubsub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240064608,"owners_count":19742347,"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":["pubsub","trailpack","trails"],"created_at":"2024-11-08T20:16:11.515Z","updated_at":"2026-04-28T07:30:19.074Z","avatar_url":"https://github.com/trailsjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# trailpack-pubsub\n:package: Redis Pub/Sub implementation for Trails.js app\n\n[npm-image]: https://img.shields.io/npm/v/trailpack-pubsub.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/trailpack-pubsub\n[ci-image]: https://img.shields.io/travis/trailsjs/trailpack-pubsub/master.svg?style=flat-square\n[ci-url]: https://travis-ci.org/trailsjs/trailpack-pubsub\n[daviddm-image]: http://img.shields.io/david/trailsjs/trailpack-pubsub.svg?style=flat-square\n[daviddm-url]: https://david-dm.org/trailsjs/trailpack-pubsub\n[codeclimate-image]: https://img.shields.io/codeclimate/github/trailsjs/trailpack-pubsub.svg?style=flat-square\n[codeclimate-url]: https://codeclimate.com/github/trailsjs/trailpack-pubsub\n[gitter-image]: http://img.shields.io/badge/+%20GITTER-JOIN%20CHAT%20%E2%86%92-1DCE73.svg?style=flat-square\n[gitter-url]: https://gitter.im/trailsjs/trails\n\n[![Gitter][gitter-image]][gitter-url]\n[![NPM version][npm-image]][npm-url]\n[![Build status][ci-image]][ci-url]\n[![Dependency Status][daviddm-image]][daviddm-url]\n[![Code Climate][codeclimate-image]][codeclimate-url]\n\nProvides ability to send/receive messages using Redis Pub/Sub\n\nA pretty simple Pub/Sub system between your Trails.js applications.\n\n## Install\n\n```bash\n$ npm install --save trailpack-pubsub\n```\n## Usage\n\n### Configure\nLoad in your trailpack config\n\n```javascript\n// config/main.js\nmodule.exports = {\n  // ...\n  packs: [\n    require('trailpack-core'),\n    require('trailpack-router'),\n    // ...\n    require('trailpack-pubsub')\n  ]\n}\n```\n\n### Configure connection\n```javascript\n// config/pubsub.js\n\nmodule.exports = {\n  /**\n   * Redis connection settings\n   * @see {@link https://github.com/NodeRedis/node_redis#rediscreateclient}\n   * @type {Object}\n   */\n  connection: {\n    host: '127.0.0.1',\n    post: 6370\n  },\n\n  /**\n   * Default channel that will be used to publish events if no specific channel defined\n   * @type {String}\n   */\n  defaultChannel: 'trails-channel',\n\n  /**\n   * List of global handlers\n   * @type {Object}\n   */\n  handlers: {\n\n    onSubscribe: function(channel, count) {},\n\n    onError: function (err) {},\n\n    onMessage: function (event, message) {}\n  }\n}\n```\n\nDon't forget to add new config file into `config/index.js`\n\n```javascript\nexports.pubsub = require('./pubsub')\n```\n\n\n### Subscribing to events\n\nRight now you could subscribe to any event anywhere in your app\n\n```javascript\n// Add a new subscription to specific event inside application\nthis.app.pubsub.on('event', (data) =\u003e {\n  // ...\n})\n```\n\nAnother way to handle all events is `handlers.onMessage()` method in `config/pubsub.js`\n\n```javascript\nmodule.exports = {\n\n  //...\n  handlers: {\n\n    onMessage: function (event, message) {\n      // Will handle all events/messages from other apps\n    }\n  }\n}\n```\n\n### Publish message\n\nYou could publish event to other applications using `pubsub.publish()` method\n\n```javasctipt\nthis.app.pubsub.publish('some-event', { some: 'data' })\n```\n\n### Handling Errors\n\nRight now there is only one place for handling errors in your app.\n\nYou could add `handlers.onError` function into your `config/pubsub.js` file\n\n\n## Contributing\nWe love contributions! Please check out our [Contributor's Guide](https://github.com/trailsjs/trails/blob/master/CONTRIBUTING.md) for more\ninformation on how our projects are organized and how to get started.\n\n\n## License\n[MIT](https://github.com/trailsjs/trailpack-mongoose/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailsjs%2Ftrailpack-pubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrailsjs%2Ftrailpack-pubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailsjs%2Ftrailpack-pubsub/lists"}