{"id":47817647,"url":"https://github.com/zio/zio-nats","last_synced_at":"2026-04-03T18:49:40.863Z","repository":{"id":340675768,"uuid":"1020899384","full_name":"zio/zio-nats","owner":"zio","description":null,"archived":false,"fork":false,"pushed_at":"2026-02-26T00:01:34.000Z","size":22,"stargazers_count":1,"open_issues_count":1,"forks_count":8,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-26T04:06:05.515Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zio.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-16T15:04:56.000Z","updated_at":"2025-10-24T10:05:56.000Z","dependencies_parsed_at":"2026-02-26T04:11:53.428Z","dependency_job_id":null,"html_url":"https://github.com/zio/zio-nats","commit_stats":null,"previous_names":["zio/zio-nats"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/zio/zio-nats","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zio%2Fzio-nats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zio%2Fzio-nats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zio%2Fzio-nats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zio%2Fzio-nats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zio","download_url":"https://codeload.github.com/zio/zio-nats/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zio%2Fzio-nats/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31370218,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T17:53:18.093Z","status":"ssl_error","status_checked_at":"2026-04-03T17:53:17.617Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":[],"created_at":"2026-04-03T18:49:40.315Z","updated_at":"2026-04-03T18:49:40.854Z","avatar_url":"https://github.com/zio.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zio-nats\n\nA lightweight ZIO 2.x wrapper around the official Java NATS client (jnats).\n\nFeatures:\n- ZLayer-based managed connection acquisition \u0026 clean shutdown via `Nats.live` / `Nats.liveZIO`\n- Simple publish \u0026 request APIs (string or byte array)\n- Streaming consume API via ZStream using a NATS Dispatcher bridged through a ZIO Queue\n- Minimal service (`Nats`) you pull from the environment with `ZIO.service[Nats]`\n- Configurable via ZIO Config (env vars or system properties by default)\n\n## Usage\n\nProvide the layer and obtain the `Nats` service:\n\n```scala\nimport zio.*\nimport zio.nats.*\n\nval program = for {\n  nats \u003c- ZIO.service[Nats]\n  _    \u003c- nats.publishString(\"demo.events\", \"hello world\")\n  msg  \u003c- nats\n            .subscribe(\"demo.events\")\n            .take(1)\n            .runHead\n            .someOrFail(new RuntimeException(\"No message received\"))\n  _    \u003c- Console.printLine(s\"Received: ${msg.asString()}\")\n} yield ()\n\nval run = program.provide(Nats.live(NatsConfig.default), Scope.default)\n```\n\n### Requests\n\n```scala\nfor {\n  nats \u003c- ZIO.service[Nats]\n  response \u003c- nats.requestString(\"service.echo\", \"ping\", 2.seconds)\n} yield response\n```\n\n(Requires some service already replying on that subject.)\n\n### Raw byte APIs\n\nIf you want lower-level control:\n```scala\nval publishBytes: RIO[Nats, Unit] =\n  ZIO.serviceWithZIO[Nats](_.publish(\"binary.subject\", Array[Byte](1,2,3)))\n```\n\n### Layer Variants\n\nYou can derive the layer from config (env / system properties) directly:\n```scala\nval layer: ZLayer[Scope, Throwable, Nats] = Nats.live\n```\nOr provide an explicit `NatsConfig`:\n```scala\nval layerExplicit = Nats.live(NatsConfig(host = \"localhost\", port = 4222))\n```\nYou can also customize the `Options.Builder` from jnats if you need to. See [jnats docs](https://github.com/nats-io/nats.java) for details.\n```scala\nval layerCustom = Nats.live(NatsConfig.default, _.maxReconnects(5))\n```\n\n## Configuration via Environment\n\nWe use ZIO Config to load configuration (nested under `nats`). Via environment variables for example:\n\n| Variable        | Meaning                 | Default    |\n|-----------------|-------------------------|------------|\n| NATS_HOST       | Hostname                | localhost  |\n| NATS_PORT       | Port                    | 4222       |\n| NATS_USERNAME   | Username (optional)     | -          |\n| NATS_PASSWORD   | Password (optional)     | -          |\n| NATS_TLS        | Enable TLS (true/false) | false      |\n\n```scala\nval layer = Nats.live \n```\n\n## Streaming Example\n\n```scala\nimport zio.*\nimport zio.stream.*\nimport zio.nats.*\n\nval streamProgram = ZStream.serviceWithStream[Nats](_.subscribe(\"orders.created\"))\n  .map(_.asString())\n  .tap(str =\u003e Console.printLine(s\"Order event: $str\"))\n  .runDrain\n```\n\n## Testing\n\nAn integration test spec (`NatsSpec`) exercises publish / subscribe, request / reply, and queue group distribution. Run with Mill:\n\n```bash\nmill zioNats.test\n```\n\nIt uses the [java nats server runner](https://github.com/nats-io/java-nats-server-runner) and requires a NATS server being installed locally.\n\n## Notes \u0026 Future Work\n- Add request/reply helper for automatic responders\n- Add JetStream (streaming persistence) support (future)\n- Add structured error model + retries/backoff utilities\n\n## License\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzio%2Fzio-nats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzio%2Fzio-nats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzio%2Fzio-nats/lists"}