{"id":15295215,"url":"https://github.com/alex179ohm/nsq-client-rs","last_synced_at":"2025-04-13T15:59:23.791Z","repository":{"id":57646129,"uuid":"170545465","full_name":"alex179ohm/nsq-client-rs","owner":"alex179ohm","description":"NSQ client written in rust","archived":false,"fork":false,"pushed_at":"2019-12-11T13:03:41.000Z","size":336,"stargazers_count":13,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T06:51:21.248Z","etag":null,"topics":["actix","crate","nsq","nsq-client","rust","rust-crate","rust-nsq","rustlang"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/alex179ohm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-13T17:00:40.000Z","updated_at":"2021-02-26T04:54:43.000Z","dependencies_parsed_at":"2022-09-08T15:12:26.417Z","dependency_job_id":null,"html_url":"https://github.com/alex179ohm/nsq-client-rs","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex179ohm%2Fnsq-client-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex179ohm%2Fnsq-client-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex179ohm%2Fnsq-client-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex179ohm%2Fnsq-client-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alex179ohm","download_url":"https://codeload.github.com/alex179ohm/nsq-client-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248741198,"owners_count":21154252,"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":["actix","crate","nsq","nsq-client","rust","rust-crate","rust-nsq","rustlang"],"created_at":"2024-09-30T17:09:04.376Z","updated_at":"2025-04-13T15:59:23.772Z","avatar_url":"https://github.com/alex179ohm.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NSQ client written in rust [![Build Status](https://travis-ci.com/alex179ohm/nsq-client-rs.svg?branch=master)](https://travis-ci.com/alex179ohm/nsq-client-rs) [![Build status](https://ci.appveyor.com/api/projects/status/ov5ryj2r4iy2v7rp/branch/master?svg=true)](https://ci.appveyor.com/project/alex179ohm/nsq-client-rs/branch/master) [![](https://img.shields.io/crates/v/nsq-client.svg?style=flat)](https://crates.io/crates/nsq-client)\n\nSponsored by \u003ca href=\"https://tngrm.io\"\u003e\u003cimg src=\"https://tngrm.io/static/img/tngrm_black.svg\" width=\"110\"\u003e\u003c/a\u003e\n---\nA [Actix](https://actix.rs/) based client implementation for the [NSQ](https://nsq.io) realtime message processing system.\n\nNsq-client it's designed to support by default multiple Readers for Multiple Connections, readers are routed per single connection by a round robin algorithm.\n## Usage\n\nTo use nsq-client, add this to your Cargo.toml:\n```toml\n[dependencies]\nactix = \"0.7\"\nnsq-client = \"0.1.12\"\n```\n### Create your first consumer\nIn order to use nsq-client you first need to create a Reader actor which implement Handler for the type of messages you want to receive\nfrom the connections and then subscribe it to the connections to be able to receive the type of messages you've selected.\n\nAvailable messages are:\n- [Msg](https://docs.rs/nsq-client/0.1.11/nsq_client/struct.Msg.html)\n- [InFlight](https://docs.rs/nsq-client/0.1.11/nsq_client/struct.InFlight.html)\n- [OnIdentify](https://docs.rs/nsq-client/0.1.11/nsq_client/struct.OnIdentify.html)\n- [OnAuth](https://docs.rs/nsq-client/0.1.11/nsq_client/struct.OnAuth.html)\n- [OnClose](https://docs.rs/nsq-client/0.1.11/nsq_client/struct.OnClose.html) \n- [OnBackoff](https://docs.rs/nsq-client/0.1.11/nsq_client/struct.OnBackoff.html)\n- [OnResume](https://docs.rs/nsq-client/0.1.11/nsq_client/struct.OnResume.html)\n\n### Simple Consumer (SUB)\n```rust\nextern crate actix;\nextern crate nsq_client;\n\nuse std::sync::Arc;\n\nuse actix::prelude::*;\n\nuse nsq_client::{Connection, Msg, Fin, Subscribe, Config};\n\nstruct MyReader {\n    pub conn: Arc\u003cAddr\u003cConnection\u003e\u003e,\n}\n\nimpl Actor for MyReader {\n    type Context = Context\u003cSelf\u003e;\n    fn started(\u0026mut self, ctx: \u0026mut Self::Context) {\n        self.subscribe::\u003cMsg\u003e(ctx, self.conn.clone());\n    }\n}\n\nimpl Handler\u003cMsg\u003e for MyReader {\n    fn handle(\u0026mut self, msg: Msg, _: \u0026mut Self::Context) {\n        println!(\"MyReader received {:?}\", msg);\n        if let Ok(body) = String::from_utf8(msg.body) {\n              println!(\"utf8 msg: {}\", body);\n        }\n        self.conn.do_send(Fin(msg.id));\n    }\n}\n\nfn main() {\n    let sys = System::new(\"consumer\");\n    let config = Config::default().client_id(\"consumer\");\n    let c = Supervisor::start(|_| Connection::new(\n        \"test\", // \u003c- topic\n        \"test\", // \u003c- channel\n        \"0.0.0.0:4150\", // \u003c- nsqd tcp address\n        Some(config), // \u003c- config (Optional)\n        None, // secret for Auth (Optional)\n        Some(2) // \u003c- RDY (Optional default: 1)\n    ));\n    let conn = Arc::new(c);\n    let _ = MyReader{ conn: conn.clone() }.start(); // \u003c- Same thread reader\n    let _ = Arbiter::start(|_| MyReader{ conn: conn }); // \u003c- start another reader in different thread\n    sys.run();\n}\n```\n### launch nsqd\n```bash\n$ nsqd -verbose\n```\n### launch the reader\n```bash\n$ RUST_LOG=nsq_client=debug cargo run\n```\n### launch the producer\n```bash\n$ cargo run\n```\n\n[![asciicast](https://asciinema.org/a/8dZ5QgjN3WCwDhgU8mAX9BMsR.svg)](https://asciinema.org/a/8dZ5QgjN3WCwDhgU8mAX9BMsR)\n\n## Examples\n- [Simple Processing Message](https://github.com/alex179ohm/nsq-client-rs/tree/master/examples/reader)\n- [Simple Producer](https://github.com/alex179ohm/nsq-client-rs/tree/master/examples/producer)\n\n### ToDo\n- [ ] Discovery\n- [ ] TLS\n- [ ] Snappy\n- [ ] First-ready-first-served readers routing algorithm.\n\n## License\n\nLicensed under\n* MIT license (see [LICENSE](LICENSE) or \u003chttp://opensource.org/licenses/MIT\u003e)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex179ohm%2Fnsq-client-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falex179ohm%2Fnsq-client-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex179ohm%2Fnsq-client-rs/lists"}