{"id":17004774,"url":"https://github.com/gtramontina/spring-river","last_synced_at":"2026-03-08T11:39:20.830Z","repository":{"id":20253876,"uuid":"89243324","full_name":"gtramontina/spring-river","owner":"gtramontina","description":"Rapids/Rivers/Ponds – https://vimeo.com/79866979","archived":false,"fork":false,"pushed_at":"2025-03-07T16:07:41.000Z","size":1126,"stargazers_count":10,"open_issues_count":27,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-07T17:23:21.398Z","etag":null,"topics":["amqp","event-driven","eventbus","microservices","paradigm","rabbitmq"],"latest_commit_sha":null,"homepage":null,"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/gtramontina.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-24T13:27:36.000Z","updated_at":"2024-09-09T16:51:21.000Z","dependencies_parsed_at":"2023-11-21T05:34:53.022Z","dependency_job_id":"a81ff0b4-a789-42e3-9f0d-1dff83887784","html_url":"https://github.com/gtramontina/spring-river","commit_stats":{"total_commits":440,"total_committers":5,"mean_commits":88.0,"dds":"0.045454545454545414","last_synced_commit":"895e50697ff8ea9222233520a5427adcad073c82"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gtramontina%2Fspring-river","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gtramontina%2Fspring-river/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gtramontina%2Fspring-river/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gtramontina%2Fspring-river/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gtramontina","download_url":"https://codeload.github.com/gtramontina/spring-river/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243742638,"owners_count":20340676,"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","event-driven","eventbus","microservices","paradigm","rabbitmq"],"created_at":"2024-10-14T04:44:26.037Z","updated_at":"2026-03-08T11:39:20.793Z","avatar_url":"https://github.com/gtramontina.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![spring-river](https://cloud.githubusercontent.com/assets/374635/25313507/34d93b0a-2873-11e7-8667-01dba6b65072.png)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/npm/v/spring-river.svg\" alt=\"npm version\"\u003e\n  \u003cimg src=\"https://img.shields.io/npm/l/spring-river.svg\" alt=\"npm license\"\u003e\n  \u003cimg src=\"https://img.shields.io/travis/gtramontina/spring-river.svg\" alt=\"travis\"\u003e\n  \u003cimg src=\"https://img.shields.io/codeclimate/github/gtramontina/spring-river.svg\" alt=\"codeclimate score\"\u003e\n\u003c/div\u003e\n\n## Disclaimer\n\nThis library is my attempt to make a javascript version of Fred George's ([@fredgeorge](https://github.com/fredgeorge)) [RapidsRivers](https://github.com/fredgeorge/rapids_rivers) following [Zeit's Micro](https://github.com/zeit/micro) simple bootstrap approach. This is just an experiment at this point.\n\nFor more information on the Rapids/Rivers/Ponds paradigm, please refer to the links at the bottom of this file.\n\n## Usage\n\nIf you learn by looking at code first, check out `examples` directory.\n\nNow onto the step-by-step:\n\nFirst, you need to install `spring-river` as a runtime dependency:\n\n```shell\nnpm install spring-river --save\n```\n\nThis library requires an `amqp`-compatible queue. [RabbitMQ](https://www.rabbitmq.com/) works perfectly. In order to configure the queue address, you can either set the environment variable `ADDRESS` or add the `--address` (or `-a`) flag when starting your services and set the address as `amqp://…`.\n\n### River\n\nIf your microservice is the one generating \"solutions\", add a `{\"start\": \"river\"}` script, like the following, to your `package.json`:\n\n```json\n{\n  \"main\": \"index.js\",\n  \"name\": \"my-microservice-river\",\n  \"scripts\": {\n    \"start\": \"river\"\n  }\n}\n```\n\nYour `index.js` will look like the following. It accepts a `packet`, which is, for all purposes, a plain javascript object with the packet's contents, and a `publish` function, which can be used to publish conclusions back to the rapids.\n\n```javascript\nmodule.exports = (packet, publish) =\u003e {\n  packet.solution = 10;\n  publish(packet);\n};\n```\n\nTo get you service running, all you need to do is to run:\n\n```shell\nnpm start\n```\n\n### Spring\n\nIf your microservice is the one generating \"needs\", add a `{\"start\": \"spring\"}` script, like the following, to your `package.json`:\n\n```json\n{\n  \"main\": \"index.js\",\n  \"name\": \"my-microservice-spring\",\n  \"scripts\": {\n    \"start\": \"spring\"\n  }\n}\n```\n\nYour `index.js` will look like the following. It accepts a `publish` function, which can be used to publish conclusions (a need is a conclusion) to the rapids.\n\n```javascript\nmodule.exports = (publish) =\u003e {\n  setInterval(() =\u003e {\n    publish({need: 'rental_car_offer'});\n  }, 5000)\n};\n```\n\nTo get you service running, all you need to do is to run:\n\n```shell\nnpm start\n```\n\n### Predicates\n\nBy definition, your exported function will be called whenever a packet arrives (this is so we can keep the bus a dumb pipe). In order to filter out and focus only on interesting packets, you can use decorators around your to-be-exported function. E.g.:\n\n```javascript\nconst myFilter = require('./my-filter');\n\nmodule.exports = myFilter((packet, publish) =\u003e {\n  packet.solution = 10;\n  publish(packet);\n});\n```\n\nWhere `my-filter.js` could be something that filters only packets that have `{need: 'rental_car_offer'}`:\n\n```javascript\nmodule.exports = (next) =\u003e (packet, publish) =\u003e {\n  if (packet.need === 'rental_car_offer') {\n    next(packet, publish);\n  }\n}\n```\n\nThis library ships with a few built-in predicates that you might find useful (perhaps these are candidates to be moved out into their own modules, as these are just very simple functions).\n\n\u003cdetails\u003e\n  \u003csummary\u003e`forbid-keys`: filters out packets that contain any of the given keys;\n  \u003c/summary\u003e\n\n  \u003e *Parameters:*\n  \u003e `(...string)`: a list of forbidden keys\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e`require-keys`: filters out packets that _do not_ contain _all_ given keys;\n  \u003c/summary\u003e\n\n  \u003e *Parameters:*\n  \u003e `(...string)`: a list of required keys\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e`require-values`: filters out packets that _do not_ contain _all_ given key-value pairs;\n  \u003c/summary\u003e\n\n  \u003e *Parameters:*\n  \u003e `(object)`: the object with the required key-value pairs\n\n\u003c/details\u003e\n\n#### Usage\n\nThe following example is interested in packets that contain the `{need: 'rental_car_offer'}` key-value pair and does not have a `solution` key:\n\n```javascript\nconst predicates = require('spring-river/predicates');\nconst {requireValues, forbidKeys} = predicates;\n\nmodule.exports = predicates(\n  requireValues({need: 'rental_car_offer'}),\n  forbidKeys('solution')\n)((packet, publish) =\u003e {\n  packet.solution = 10;\n  publish(packet);\n});\n\n```\n\n## Credits\n\nFirst and foremost, everything here is built based on Fred George's ([@fredgeorge](https://github.com/fredgeorge)) Rapids/Rivers/Ponds paradigm, so here's a list of resources if you want to get more familiar with this idea:\n\n* https://vimeo.com/79866979\n* https://youtu.be/2rKEveL55TY\n* https://github.com/fredgeorge/rapids_rivers\n* https://github.com/fredgeorge/microservice_workshop\n* https://www.infoq.com/news/2016/02/not-just-microservices\n\nThe structure of this module was inspired by [Zeit's Micro](https://github.com/zeit/micro), so `bin/index.js` borrows a lot from it.\n\n## License\n\nThis software is licensed under the [MIT license](http://opensource.org/licenses/MIT).\n\n---\n\n[![](https://codescene.io/projects/1137/status.svg)](https://codescene.io/projects/1137/jobs/latest-successful/results)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgtramontina%2Fspring-river","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgtramontina%2Fspring-river","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgtramontina%2Fspring-river/lists"}