{"id":16940382,"url":"https://github.com/hseeberger/pub-sub-client","last_synced_at":"2025-04-11T19:22:01.086Z","repository":{"id":42988993,"uuid":"442467556","full_name":"hseeberger/pub-sub-client","owner":"hseeberger","description":"Google Cloud Pub/Sub client library in Rust.","archived":false,"fork":false,"pushed_at":"2023-10-15T15:54:53.000Z","size":109,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T15:10:08.770Z","etag":null,"topics":["cloud-pub-sub","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/hseeberger.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":"2021-12-28T13:11:33.000Z","updated_at":"2024-07-11T02:15:13.000Z","dependencies_parsed_at":"2023-02-06T14:45:15.730Z","dependency_job_id":null,"html_url":"https://github.com/hseeberger/pub-sub-client","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hseeberger%2Fpub-sub-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hseeberger%2Fpub-sub-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hseeberger%2Fpub-sub-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hseeberger%2Fpub-sub-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hseeberger","download_url":"https://codeload.github.com/hseeberger/pub-sub-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248465351,"owners_count":21108244,"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":["cloud-pub-sub","rust"],"created_at":"2024-10-13T21:06:56.599Z","updated_at":"2025-04-11T19:22:01.062Z","avatar_url":"https://github.com/hseeberger.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Google Cloud Pub/Sub client\n\n[![Crates.io][crates-badge]][crates-url]\n[![license][license-badge]][license-url]\n[![build][build-badge]][build-url]\n\n[crates-badge]: https://img.shields.io/crates/v/pub-sub-client\n[crates-url]: https://crates.io/crates/pub-sub-client\n[license-badge]: https://img.shields.io/github/license/hseeberger/pub-sub-client\n[license-url]: https://github.com/hseeberger/pub-sub-client/blob/main/LICENSE\n[build-badge]: https://img.shields.io/github/actions/workflow/status/hseeberger/pub-sub-client/ci.yaml\n[build-url]: https://github.com/hseeberger/pub-sub-client/actions/workflows/ci.yaml\n\nGoogle Cloud Pub/Sub client library in [Rust](https://www.rust-lang.org/). Currently publishing, pulling and acknowledging are supported, but no management tasks like creating topics or subscriptions.\n\nMessages can either be published/pulled as raw or, if the payload is JSON data, serialized from/deserialized into domain messages (structs or enums) via [Serde](https://serde.rs/) and [Serde JSON](https://docs.serde.rs/serde_json). Both raw `RawPulledMessage`s and \"typed\" `PulledMessage`s expose metadata like message ID, acknowledge ID, attributes, etc.\n\nAside from straight forward deserialization it is also possible to first transform the pulled JSON values before deserizlizing into domain messages which allows for generally adjusting the JSON structure as well as schema evolution.\n\n## Usage\n\nTypically we want to use domain message:\n\n``` rust\n#[derive(Debug, Serialize, Deserialize)]\nstruct Message {\n    text: String,\n}\n```\n\nTo publish `Message` we need to derive `Serialize` and to pull it we need to derive `Deserialize`.\n\nFirst create a `PubSubClient`, giving the path to a service account key file and the duration to refresh access tokens before they expire:\n\n``` rust\nlet pub_sub_client = PubSubClient::new(\n    \"secrets/cryptic-hawk-336616-e228f9680cbc.json\",\n    Duration::from_secs(30),\n)?;\n```\n\nThings could go wrong, e.g. if the service account key file does not exist or is malformed, hence a `Result` is returned.\n\nThen we call `publish` to publish some `messages` using the given `TOPIC_ID` and – if all is good – get back the message IDs; we do not use an ordering key nor a request timeout here and below for simplicity:\n\n``` rust\nlet messages = vec![\"Hello\", \"from pub-sub-client\"]\n    .iter()\n    .map(|s| s.to_string())\n    .map(|text| Message { text })\n    .collect::\u003cVec\u003c_\u003e\u003e();\nlet message_ids = pub_sub_client\n    .publish(TOPIC_ID, messages, None, None)\n    .await?;\nlet message_ids = message_ids.join(\", \");\nprintln!(\"Published messages with IDs: {message_ids}\");\n```\n\nNext we call `pull` to get at most the given `42` messages from the given `SUBSCRIPTION_ID`:\n\n``` rust\nlet pulled_messages = pub_sub_client\n    .pull::\u003cMessage\u003e(SUBSCRIPTION_ID, 42, None)\n    .await?;\n```\n\nOf course pulling which happens via HTTP could fail, hence we get back another `Result`.\n\nFinally we handle the pulled messages; for simplicity we only deal with the happy path here, i.e. when the deserialization was successful:\n\n``` rust\nfor pulled_message in pulled_messages {\n    match pulled_message.message {\n        Ok(m) =\u003e println!(\"Pulled message with text \\\"{}\\\"\", m.text),\n        Err(e) =\u003e eprintln!(\"ERROR: {e}\"),\n    }\n\n    pub_sub_client\n        .acknowledge(SUBSCRIPTION_ID, vec![\u0026pulled_message.ack_id], None)\n        .await?;\n    println!(\"Acknowledged message with ID {}\", pulled_message.id);\n}\n```\n\nFor successfully deserialized messages we call `acknowledge` with the acknowledge ID taken from the envelope.\n\n## Contribution policy ##\n\nContributions via GitHub pull requests are gladly accepted from their original author. Along with\nany pull requests, please state that the contribution is your original work and that you license the\nwork to the project under the project's open source license. Whether or not you state this\nexplicitly, by submitting any copyrighted material via pull request, email, or other means you agree\nto license the material under the project's open source license and warrant that you have the legal\nauthority to do so.\n\n## License ##\n\nThis code is open source software licensed under the\n[Apache 2.0 License](\"http://www.apache.org/licenses/LICENSE-2.0.html\").\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhseeberger%2Fpub-sub-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhseeberger%2Fpub-sub-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhseeberger%2Fpub-sub-client/lists"}