{"id":25720104,"url":"https://github.com/gregwhitaker/nats-pubsub-example","last_synced_at":"2026-06-16T15:31:30.359Z","repository":{"id":82732565,"uuid":"118943446","full_name":"gregwhitaker/nats-pubsub-example","owner":"gregwhitaker","description":"An example of using NATS for pubsub messaging","archived":false,"fork":false,"pushed_at":"2018-01-26T00:34:26.000Z","size":93,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T17:41:32.830Z","etag":null,"topics":["messaging","nats","nats-messaging","natsio","publish-subscribe","pubsub"],"latest_commit_sha":null,"homepage":"","language":"Java","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/gregwhitaker.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":"2018-01-25T17:14:04.000Z","updated_at":"2022-05-03T17:08:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"9cb26225-7d3c-46bd-b620-88b1969356d6","html_url":"https://github.com/gregwhitaker/nats-pubsub-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gregwhitaker/nats-pubsub-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregwhitaker%2Fnats-pubsub-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregwhitaker%2Fnats-pubsub-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregwhitaker%2Fnats-pubsub-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregwhitaker%2Fnats-pubsub-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gregwhitaker","download_url":"https://codeload.github.com/gregwhitaker/nats-pubsub-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregwhitaker%2Fnats-pubsub-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34412785,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["messaging","nats","nats-messaging","natsio","publish-subscribe","pubsub"],"created_at":"2025-02-25T17:36:35.270Z","updated_at":"2026-06-16T15:31:30.354Z","avatar_url":"https://github.com/gregwhitaker.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nats-pubsub-example\n[![Build Status](https://travis-ci.org/gregwhitaker/nats-pubsub-example.svg?branch=master)](https://travis-ci.org/gregwhitaker/nats-pubsub-example)\n\nAn example of using [NATS](https://nats.io) to do pubsub messaging.\n\nThis example starts a service that publishes CPU metrics every second to a `metrics-pubsub` topic. The topic is subscribed to by one-to-many clients each receiving the CPU metrics messages published by the service.\n\n## Background\nNATS publish subscribe is a one-to-many communication. A publisher sends a message on a subject. Any active subscriber listening on that subject receives the message. \n\nThe NATS pubsub model is \"At-Most-Once-Delivery\". If a subscriber is not listening on the subject (no subject match), or is not active when the message is sent, the message is not received. \n\nMore information can be found in the [NATS Documentation](https://nats.io/documentation/concepts/nats-pub-sub/).\n\n## Prerequisites\nThe examples require a local NATS server to be running. To start a NATS server as a Docker container run the following commands:\n\n    $ docker pull nats\n    $ docker run -p 4222:4222 -p 6222:6222 -p 8222:8222 -d --name nats-main nats\n\n## Running the Example\n### Start the PubSub Client\nYou can start the [PubSub Client](pubsub-client/README.md) using the following command:\n\n    $ ./gradlew :pubsub-client:run\n    \nOnce the client and service is running you will see messages similar to the following in the terminal:\n\n    [main] INFO nats.example.pubsub.client.Main - Starting NATS Example PubSub Client\n    [jnats-subscriptions] INFO nats.example.pubsub.client.Main - Received Message: \"{\\\"cpuPercentage\\\":0.0,\\\"totalPhysicalMemory\\\":16384.0,\\\"freePhysicalMemory\\\":525.0}\"\n    [jnats-subscriptions] INFO nats.example.pubsub.client.Main - Received Message: \"{\\\"cpuPercentage\\\":0.27,\\\"totalPhysicalMemory\\\":16384.0,\\\"freePhysicalMemory\\\":454.0}\"\n    [jnats-subscriptions] INFO nats.example.pubsub.client.Main - Received Message: \"{\\\"cpuPercentage\\\":0.06,\\\"totalPhysicalMemory\\\":16384.0,\\\"freePhysicalMemory\\\":362.0}\"\n\nYou can start multiple client instances to see them each receiving the same messages.\n\n### Start the PubSub Service\nYou can start the [PubSub Service](pubsub-service/README.md) using the following command:\n\n    $ ./gradlew :pubsub-service:run\n\nOnce the service is running you will see messages similar to the following in the terminal:\n\n    [main] INFO nats.example.pubsub.service.Main - Starting NATS Example PubSub Service\n    [Timer-0] INFO nats.example.pubsub.service.MetricsPublishTask - Publishing: {\"cpuPercentage\":0.0,\"totalPhysicalMemory\":16384.0,\"freePhysicalMemory\":552.0}\n    [Timer-0] INFO nats.example.pubsub.service.MetricsPublishTask - Publishing: {\"cpuPercentage\":0.28,\"totalPhysicalMemory\":16384.0,\"freePhysicalMemory\":448.0}\n    [Timer-0] INFO nats.example.pubsub.service.MetricsPublishTask - Publishing: {\"cpuPercentage\":0.04,\"totalPhysicalMemory\":16384.0,\"freePhysicalMemory\":564.0}\n\n## Bugs and Feedback\nFor bugs, questions and discussions please use the [Github Issues](https://github.com/gregwhitaker/nats-pubsub-example/issues).\n\n## License\nMIT License\n\nCopyright (c) 2018 Greg Whitaker\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregwhitaker%2Fnats-pubsub-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregwhitaker%2Fnats-pubsub-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregwhitaker%2Fnats-pubsub-example/lists"}