{"id":22514684,"url":"https://github.com/jdizm/gcloud-pub-sub","last_synced_at":"2025-07-04T16:35:33.375Z","repository":{"id":254925858,"uuid":"651890852","full_name":"JDIZM/gcloud-pub-sub","owner":"JDIZM","description":"an example using gcloud pubsub, cloudevents and functions framework","archived":false,"fork":false,"pushed_at":"2024-08-26T23:27:36.000Z","size":210,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T03:27:44.897Z","etag":null,"topics":["cloudevents","events","functions","gcloud","gcp","pubsub","serverless"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JDIZM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-06-10T12:06:58.000Z","updated_at":"2024-08-26T23:28:50.000Z","dependencies_parsed_at":"2024-08-27T02:08:05.981Z","dependency_job_id":"b62e22aa-0e33-45f2-9df3-c78ab4a15255","html_url":"https://github.com/JDIZM/gcloud-pub-sub","commit_stats":null,"previous_names":["jdizm/gcloud-pub-sub"],"tags_count":0,"template":false,"template_full_name":"JDIZM/vite-node-ts-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDIZM%2Fgcloud-pub-sub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDIZM%2Fgcloud-pub-sub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDIZM%2Fgcloud-pub-sub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDIZM%2Fgcloud-pub-sub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JDIZM","download_url":"https://codeload.github.com/JDIZM/gcloud-pub-sub/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245954167,"owners_count":20699782,"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":["cloudevents","events","functions","gcloud","gcp","pubsub","serverless"],"created_at":"2024-12-07T03:20:27.866Z","updated_at":"2025-03-28T01:44:40.949Z","avatar_url":"https://github.com/JDIZM.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gcloud-pub-sub\n\nThis project demonstrates how to work with Google Cloud Pub/Sub using Node.js, including publishing messages, listening for messages, and setting up Cloud Functions triggered by Pub/Sub events.\n\n## Setup\n\n1. Install dependencies:\n\n   ```\n   npm install\n   ```\n\n2. Set up Google Cloud credentials:\n\n   - Run `gcloud init` to set up the project and credentials.\n   - Alternatively, you can use one of these methods:\n\n     ```zsh\n     # Login as a user:\n     gcloud auth application-default login\n\n     # Set a service account as the default in your env:\n     export GOOGLE_APPLICATION_CREDENTIALS=$HOME/path/to/your/gcloud.json\n     ```\n\n3. View active configurations:\n\n   ```\n   gcloud config list\n   ```\n\n4. Set your project:\n   ```\n   gcloud config set project YOUR_PROJECT_ID\n   ```\n\n## Pub/Sub Operations\n\n### Create a Topic and Subscription\n\n```zsh\ngcloud pubsub topics create test-topic\ngcloud pubsub subscriptions create test-sub-1 --topic test-topic\n```\n\n### Send a Message\n\nTo publish a message to the Pub/Sub topic:\n\n```zsh\nnpm run send\n```\n\nThis script uses `src/sendMessage.ts` to publish a message to the \"test-topic\" topic.\n\n### Listen for Messages\n\nTo listen for messages on the subscription:\n\n```zsh\nnpm run listen\n```\n\nThis script uses `src/listen.ts` to listen for messages on the \"test-sub-1\" subscription and process them, including parsing CloudEvents.\n\n## Cloud Functions\n\n### Testing a Function Locally\n\n1. Build the project:\n\n   ```\n   npm run build\n   ```\n\n2. Navigate to the function directory:\n\n   ```\n   cd dist/functions/events/helloWorld\n   ```\n\n3. Run the function locally:\n   ```\n   npx @google-cloud/functions-framework --target=helloWorld\n   ```\n\nThis will start a local server at `http://localhost:8080/`.\n\n### Sending a CloudEvent to a Local Function\n\nUse the following code to send a CloudEvent to your local function:\n\n```js\nimport { httpTransport, emitterFor, CloudEvent, CloudEventV1 } from \"cloudevents\";\nconst emit = emitterFor(httpTransport(\"http://localhost:8080/\"));\n\nconst ce: CloudEventV1\u003cstring\u003e = {\n  specversion: \"1.0\",\n  source: \"/some/source\",\n  type: \"example\",\n  id: \"1234\",\n  data: JSON.stringify({ foo: \"bar\" })\n};\n\nconst event = new CloudEvent(ce);\n\nemit(event);\n```\n\nRun this code using:\n\n```zsh\nnpm run dev\n```\n\n### Deploying a Function\n\nTo deploy your function to Google Cloud Functions, follow the [official deployment guide](https://cloud.google.com/functions/docs/deploy).\n\n## Additional Resources\n\n- [Google Cloud Pub/Sub Documentation](https://cloud.google.com/pubsub/docs)\n- [Cloud Functions Documentation](https://cloud.google.com/functions/docs)\n- [CloudEvents SDK for JavaScript](https://github.com/cloudevents/sdk-javascript)\n- [Terraform Google Cloud Functions Resource](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloudfunctions_function)\n\n## Contributing\n\nFeel free to submit issues or pull requests if you have suggestions for improvements or find any bugs.\n\n\u003c!-- ## License\n\n[Include your license information here] --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdizm%2Fgcloud-pub-sub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdizm%2Fgcloud-pub-sub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdizm%2Fgcloud-pub-sub/lists"}