{"id":14067178,"url":"https://github.com/andodet/googlePubsubR","last_synced_at":"2025-07-30T00:32:41.215Z","repository":{"id":44948711,"uuid":"425024608","full_name":"andodet/googlePubsubR","owner":"andodet","description":"R interface for Google Pub/Sub","archived":false,"fork":false,"pushed_at":"2023-03-03T08:58:19.000Z","size":163,"stargazers_count":10,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-13T11:15:02.392Z","etag":null,"topics":["api-client","google-pubsub","rstats"],"latest_commit_sha":null,"homepage":"https://andodet.github.io/googlePubsubR/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andodet.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","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":"2021-11-05T17:02:32.000Z","updated_at":"2024-08-29T13:37:00.000Z","dependencies_parsed_at":"2024-08-13T07:12:03.365Z","dependency_job_id":"0e162bd7-e259-410a-9545-25d953e879d4","html_url":"https://github.com/andodet/googlePubsubR","commit_stats":{"total_commits":36,"total_committers":1,"mean_commits":36.0,"dds":0.0,"last_synced_commit":"1c49c79836dab5e32ae5e52da143ad868e068e91"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andodet%2FgooglePubsubR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andodet%2FgooglePubsubR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andodet%2FgooglePubsubR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andodet%2FgooglePubsubR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andodet","download_url":"https://codeload.github.com/andodet/googlePubsubR/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228065222,"owners_count":17863965,"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":["api-client","google-pubsub","rstats"],"created_at":"2024-08-13T07:05:28.220Z","updated_at":"2024-12-04T07:30:45.980Z","avatar_url":"https://github.com/andodet.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"# `googlePubsubR`\n\n[![R-CMD-check-ascran](https://github.com/andodet/googlePubsubR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/andodet/googlePubsubR/actions/workflows/R-CMD-check.yaml)\n[![testthat](https://github.com/andodet/googlePubsubR/actions/workflows/testthat.yaml/badge.svg)](https://github.com/andodet/googlePubsubR/actions/workflows/testthat.yaml)\n[![codecov](https://codecov.io/gh/andodet/googlePubsubR/branch/master/graph/badge.svg?token=OTBHY3F1KD)](https://app.codecov.io/gh/andodet/googlePubsubR)\n\nThis library offers an easy to use interface for the Google Pub/Sub REST API\n(docs [here](https://cloud.google.com/pubsub/docs/reference/rest)).\n\nNot an official Google product.\n\n## Setup\n\nYou can install the package from CRAN or get the `dev` version from Github:\n```r\ninstall.packages(\"googlePubsubR\")\n\n# Or get the dev version from Github\ndevtools::install_github(\"andodet/googlePubsubR@dev\")\n```\n\nIn order to use the library, you will need:\n\n* An active GCP project\n* The Pub/Sub API correctly activated\n* JSON credentials for a service account or another method of authentication (e.g token). You can pass the\npath of the file as an argument to `pubsub_auth` or setting an `GCP_AUTH_FILE` env variable.\n* A `GCP_PROJECT` env variable set with a valid GCP project id. Since `0.0.3`, GCP project id can also be set \nusing `ps_project_set`.\n\n## Usage\n\nOn a very basic level, the library can be used to publish messages, pull and acknowledge them.  \nThe following example shows how to:\n\n1. Create topics and subscriptions\n2. Encode a dataframe as a Pub/Sub message\n3. Publish a message\n4. Pull and decode messages from a Pub/Sub subscription\n5. Delete resources\n\n```r\nlibrary(googlePubsubR)\nlibrary(base64enc)\nlibrary(jsonlite)\n\n# Authenticate \npubsub_auth()\n\n# Create resources\ntopic_readme \u003c- topics_create(\"readme-topic\")\nsub_readme \u003c- subscriptions_create(\"readme-sub\", topic_readme)\n\n# Prepare the message\nmsg \u003c- mtcars %\u003e%\n  toJSON(auto_unbox = TRUE) %\u003e%\n  # Pub/Sub expects a base64 encoded string\n  msg_encode() %\u003e% \n  PubsubMessage() \n\n# Publish the message!\ntopics_publish(msg, topic_readme)\n\n# Pull the message from server\nmsgs_pull \u003c- subscriptions_pull(sub_readme)\n\nmsg_decoded \u003c- msgs_pull$receivedMessages$message$data %\u003e%\n  msg_decode() %\u003e% \n  fromJSON()\n\nhead(msg_decoded)\n\n# Prints\n# mpg cyl disp  hp drat    wt  qsec vs am gear carb\n# Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4\n# Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4\n# Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1\n# Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1\n# Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2\n# Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1\n\n# We can acknowledge that the message has been consumed\nsubscriptions_ack(msgs_pull$receivedMessages$ackId, sub_readme)\n# [1] TRUE\n\n# A subsequent pull will return no messages from the server\nsubscriptions_pull(sub_readme)\n# named list()\n\n# Cleanup resources\ntopics_delete(topic_readme)\nsubscriptions_delete(sub_readme)\n```\n\n## Use cases\n\nThe main use-cases for Pub/Sub messaging queue:\n\n* Stream data into [Dataflow](https://cloud.google.com/dataflow) pipelines\n* Trigger workflows hosted in Cloud Run or Cloud Functions\n* Expand interactivity in Shiny dashboards (more on this [here](inst/shiny/consumer_example/readme.md)).\n* Add event driven actions in [`{plumbr}`](https://www.rplumber.io/)\n\n## Contributing\n\nIn order to contribute to `googlePubsubR` you'll need to go through the following steps:\n\n1. Set up a GCP project and create a service account with Pub/Sub admin rights.\n2. Download a JSON key for the newly created account. Naming the file `.gcp_creds.json` and placing\nit in the package root folder will make it automatically gitignored.\n3. Set up the following env vars (either through a tool like `direnv` or a `.Renviron` file).\n\n    ```\n    GCP_AUTH_FILE=\u003cpaht_to_json_auth_file\u003e\n    GCP_PROJECT=\u003cgcp_project_id_string\u003e\n    ```\n4. Check everything is set up correctly by running a test run via `devtools::test()`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandodet%2FgooglePubsubR","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandodet%2FgooglePubsubR","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandodet%2FgooglePubsubR/lists"}