{"id":17085580,"url":"https://github.com/hisorange/circuit","last_synced_at":"2025-04-12T21:37:02.050Z","repository":{"id":40400550,"uuid":"387508899","full_name":"hisorange/circuit","owner":"hisorange","description":"Versatile Messaging library written in Typescript.","archived":false,"fork":false,"pushed_at":"2023-10-19T11:23:08.000Z","size":616,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-05T06:51:13.984Z","etag":null,"topics":["messaging","pubsub","redis","rpc","typescript"],"latest_commit_sha":null,"homepage":"https://hisorange.me","language":"TypeScript","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/hisorange.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","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":"2021-07-19T15:20:32.000Z","updated_at":"2024-08-13T06:29:41.000Z","dependencies_parsed_at":"2023-02-08T03:17:23.237Z","dependency_job_id":null,"html_url":"https://github.com/hisorange/circuit","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hisorange%2Fcircuit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hisorange%2Fcircuit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hisorange%2Fcircuit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hisorange%2Fcircuit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hisorange","download_url":"https://codeload.github.com/hisorange/circuit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239979035,"owners_count":19728452,"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":["messaging","pubsub","redis","rpc","typescript"],"created_at":"2024-10-14T13:25:16.764Z","updated_at":"2025-02-22T05:31:14.584Z","avatar_url":"https://github.com/hisorange.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ![Circuit Logo](https://user-images.githubusercontent.com/3441017/126361006-5272a10e-d123-404d-90ea-60a832258eec.png)\n\n## Circuit - Versatile Messaging Solution written in Typescript\n\n[![Version](https://badge.fury.io/gh/hisorange%2Fcircuit.svg)](https://badge.fury.io/gh/hisorange%2Fcircuit)\n[![Build](https://github.com/hisorange/circuit/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/hisorange/circuit/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/github/hisorange/circuit/badge.svg)](https://coveralls.io/github/hisorange/circuit)\n[![GitHub license](https://img.shields.io/github/license/hisorange/circuit)](https://github.com/hisorange/circuit/blob/main/LICENSE)\n\nEasy to use package to manage asynchronous messaging through multiple medium. Supports the most common publish / subscribe, and RPC (Remote Procedure Call) methodologies.\n\nWhy should you use it? Because it's **built for progression**!\n\nIt's written for projects where the transporting medium will change overtime; There are solutions with support a single medium and all of it's advantages.\n\nBut as far as we aware, most of the project **starts small** and hopefully they **grow** requirements over time, so it would be utmost wasteful to start your micro application on a high throughput\nmessaging medium like kafka.\n\nOut of the box the package starts with a simple in-memory transport, with this you can kickstart your project without external requirements.\nAnd as time goes you can easily upgrade to better transports like redis, amqp, etc... with just a single line of code, so no need for refactoring!\n\n### Getting Started\n\n---\n\n```sh\nnpm i @hisorange/circuit\n# or\nyarn add @hisorange/circuit\n```\n\n### Example: Remote Procedure Call\n\n---\n\n```ts\n// Initialize your transport driver\nconst transport = new IoRedisTransport();\n\n// Initialize the nodes (different machines IRL)\nconst node1 = new Circuit('node1', transport);\nconst node2 = new Circuit('node2', transport);\n\n// Estabilize the connections\nawait node1.connect();\nawait node2.connect();\n\n// Create a responder\nawait node1.respond\u003cSumAction\u003e('sum' (msg) =\u003e msg.content.a + msg.content.b);\n\n// Request the responder to execute the call\nassert(await node2.request\u003cSumAction\u003e('sum', { a: 2, b: 2}) === 4);\n```\n\n**Request options**\n\n| Key     | Default | Description                                     |\n| ------- | ------- | ----------------------------------------------- |\n| **ttl** | 60000   | Maximum wait time before the message is ignored |\n\n**Response options**\n\n| Key             | Default  | Description                  |\n| --------------- | -------- | ---------------------------- |\n| **concurrency** | Infinity | Maximum concurrent execution |\n\n### Example: Publish / Subscribe\n\n---\n\n```ts\nconst node = new Circuit();\n\n// Simply publish the event you want to broadcast\nnode.publish\u003cUserCreatedEvent\u003e('user.created', user);\n\n// And receive it on every listening node ^.^\nnode.subscribe\u003cUserCreatedEvent\u003e('user.created', sendWelcomeEmailToUser);\n```\n\n### Technicalities\n\n---\n\n**TypeScript**: Everything is written in typescript from the get go, so You can have the best DX possible :)\n\n**Response Routing**: When You are using the RPC request/respond model, the package manages the responses on a single channel to reduce the load on the messaging queue, with this small solution the queue does not have to open and close channels on every single RPC call.\n\n**Network Mapping**: Before You send a request the circuit checks if there is anyone to serve it, this helps to prevent hanging requests. Each circuits on the network communicates their services to every other circuit, so the requests can be routed to specific actors.\n\n### Supported Transport Mediums\n\n| Transport    | Dependency                                       |   Support   | Notes                                 |\n| :----------- | ------------------------------------------------ | :---------: | ------------------------------------- |\n| **InMemory** | -                                                |      ✓      | Emulates an external queue's behavior |\n| **Redis**    | [ioredis](https://www.npmjs.com/package/ioredis) |      ✓      | Excellent for smaller installations   |\n| **RabbitMQ** | [amqplib](https://www.npmjs.com/package/ioredis) | Coming Soon | Purpose designed messaging platform   |\n| **NATS**     | -                                                | Coming Soon | Fast and small messaging platform     |\n| **Kafka**    | -                                                |      -      | High throughput scalable solution     |\n\n### Links\n\n---\n\n- [GitHub](https://github.com/hisorange/circuit)\n- [NPM](https://www.npmjs.com/package/@hisorange/circuit)\n- [GPM](https://github.com/hisorange/circuit/packages/907960)\n\n### What's with the weird name?\n\n---\n\nThis package is part of a theme where I am trying to reuse the hardware namings in code and let the programers build on familiar known solutions. The circuit represents the circuit board similar to what we have on a PCB the listeners connect to lines and the board is simply handling the connections between them.\n\n### Changelog\n\n---\n\nTrack changes in the [Changelog](./changelog.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhisorange%2Fcircuit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhisorange%2Fcircuit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhisorange%2Fcircuit/lists"}