{"id":16462607,"url":"https://github.com/sametsahindogan/nats-message-channel","last_synced_at":"2026-05-03T22:33:37.856Z","repository":{"id":50776255,"uuid":"252213606","full_name":"sametsahindogan/nats-message-channel","owner":"sametsahindogan","description":":pushpin: Implementation of NATS MQ \u0026 websocket protocol in NodeJS.","archived":false,"fork":false,"pushed_at":"2021-05-30T06:10:39.000Z","size":4496,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-06T01:40:12.850Z","etag":null,"topics":["javascript","nats","nats-mq","nats-server","nats-streaming","nodejs","notifications","php","websocket-protocol","websocket-server"],"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/sametsahindogan.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":"2020-04-01T15:25:30.000Z","updated_at":"2021-12-22T09:20:27.000Z","dependencies_parsed_at":"2022-09-11T15:41:11.147Z","dependency_job_id":null,"html_url":"https://github.com/sametsahindogan/nats-message-channel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sametsahindogan/nats-message-channel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sametsahindogan%2Fnats-message-channel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sametsahindogan%2Fnats-message-channel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sametsahindogan%2Fnats-message-channel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sametsahindogan%2Fnats-message-channel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sametsahindogan","download_url":"https://codeload.github.com/sametsahindogan/nats-message-channel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sametsahindogan%2Fnats-message-channel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32587819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"ssl_error","status_checked_at":"2026-05-03T22:09:10.534Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["javascript","nats","nats-mq","nats-server","nats-streaming","nodejs","notifications","php","websocket-protocol","websocket-server"],"created_at":"2024-10-11T11:11:48.220Z","updated_at":"2026-05-03T22:33:37.836Z","avatar_url":"https://github.com/sametsahindogan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nats-message-channel\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://raw.githubusercontent.com/sametsahindogan/nats-message-channel/master/LICENSE)\n\n\u003e Implementation of [NATS MQ](https://nats.io/) with websocket protocol.\n\n# Scenario\n\nLet's say we want to send real-time notifications/messages to our users without using any 3rd party service like Socket IO or Pusher.\n\nAnd of course we want to separate it from our backend server to scale it freely.\n\n**Our implementation scenario will be as follows;**\n\n- **Step 1:** Of course, there should be an authentication process. When users first load the page, they send a message to our Websocket server with their own tokens.\n\n- **Step 2:** Our Websocket server send these credentials to the authentication channel ([via req/reply method](https://docs.nats.io/nats-concepts/reqreply)) on the NATS server.\n\n- **Step 3:** Our backend server has subscribed to the authentication channel. It performs the authentication process according to the incoming message.\n\n- **Step 4:** Once authentication is successful, our Websocket server marks this connection as authed and allows it to subscribe to the user-specific notification channel on the NATS server.\n\n- **Step 5:** When an event occurs (eg. order received), our backend server sends this notification to the user-specific notification channel on NATS server.\n\n- **Step 6:** Our websocket server receives the notification message through the NATS server and sends it to the user as real-time.\n\n\nOur websocket server is written in **NodeJS**.\n\n**Suppose that our backend project is written in PHP.** At that case our publisher and subscriber will be written in PHP.\n\n## Installation\n\nFirst of all, you should [install  to NATS server](https://docs.nats.io/nats-server/installation).\n\n\nGo to `/websocket` folder and run ;\n\n```bash\nnpm install\n```\n\nGo to `/api` folder and run;\n```bash\ncomposer install\n```\n\n## Usage\n\nWe need to run our Websocket server and Auth Subscriber.\n\n1. Go to `/api` folder and run;\n```bash\nnode app.js\n```\n\n2. For authentication, we run our authentication subscriber in our backend.\nGo to `/api` folder and run;\n```bash\nphp authSubscriber.php\n```\n\n3. Open `/client/user1.html` file on web browser then click the `subscribe` button. \n\nNow you can send a notification to the user-specific notification channels that the user is subscribed.\n\nFor example;\n\n4. Go to `/api` and run this command ( first argument is user id, second is message );\n\n```bash\nphp notificationPublisher.php 1 hello!\n```\n---\n**A screenshot of the processes in the background. You can follow the life cycle from the descriptions on terminal;**\n\n\u003ca\u003e\u003cimg src=\"https://raw.githubusercontent.com/sametsahindogan/nats-message-channel/master/lifecycle.png\"\u003e\u003c/a\u003e\n\n## Summary\n\nYou can adapt it to your own project, inspired by the architecture in this project.\n\n## License\nMIT © [Samet Sahindogan](https://raw.githubusercontent.com/sametsahindogan/nats-message-channel/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsametsahindogan%2Fnats-message-channel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsametsahindogan%2Fnats-message-channel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsametsahindogan%2Fnats-message-channel/lists"}