{"id":17966251,"url":"https://github.com/crallen/nestjs-google-pubsub","last_synced_at":"2025-03-25T07:31:37.181Z","repository":{"id":38782524,"uuid":"246825199","full_name":"crallen/nestjs-google-pubsub","owner":"crallen","description":"Subscribe to Google Cloud PubSub topics using NestJS's EventMessage handlers.","archived":false,"fork":false,"pushed_at":"2022-06-02T21:37:41.000Z","size":267,"stargazers_count":12,"open_issues_count":10,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-03-15T06:24:56.748Z","etag":null,"topics":["google-pubsub","nestjs","nodejs","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/crallen.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":"2020-03-12T12:11:15.000Z","updated_at":"2023-07-18T05:56:44.000Z","dependencies_parsed_at":"2022-09-21T09:11:43.781Z","dependency_job_id":null,"html_url":"https://github.com/crallen/nestjs-google-pubsub","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crallen%2Fnestjs-google-pubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crallen%2Fnestjs-google-pubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crallen%2Fnestjs-google-pubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crallen%2Fnestjs-google-pubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crallen","download_url":"https://codeload.github.com/crallen/nestjs-google-pubsub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222052675,"owners_count":16922754,"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":["google-pubsub","nestjs","nodejs","typescript"],"created_at":"2024-10-29T13:08:39.331Z","updated_at":"2024-10-29T13:08:40.777Z","avatar_url":"https://github.com/crallen.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nestjs-google-pubsub\n\nSubscribe to Google Cloud PubSub topics using NestJS's EventMessage handlers.\n\n## Installation\n\n```\n# NPM\nnpm install nestjs-google-pubsub\n\n# Yarn\nyarn add nestjs-google-pubsub\n```\n\n## Usage\n\nThe PubSubServer follows the same [microservice convention](https://docs.nestjs.com/microservices/basics) used by other NestJS integrations:\n\n```typescript\nimport { NestFactory } from '@nestjs/core';\nimport { PubSubServer } from 'nestjs-google-pubsub';\nimport { AppModule } from './app.module';\n\nasync function bootstrap() {\n  const app = await NestFactory.createMicroservice(AppModule, {\n    strategy: new PubSubServer({\n      projectId: 'my-gcp-project',\n      // other PubSub client options\n      topics: {\n        'my-topic': {\n          subscriptionId: 'my-subscription'\n        }\n      }\n    })\n  });\n  app.listen(() =\u003e console.log('Microservice is listening'));\n}\nbootstrap();\n```\n\nNext, set up a handler somewhere in your app:\n\n```typescript\nimport { Message } from '@google-cloud/pubsub';\nimport { Controller } from '@nestjs/common';\nimport { EventPattern } from '@nestjs/microservices';\n\n@Controller()\nexport class MyController {\n  @EventPattern('my-topic')\n  async handleMyTopicEvent(data: Message) {\n    // business logic\n  }\n}\n```\n\n## Configuration\n\nThe PubSubServer constructor takes in an options object that supports all of the same fields that the PubSub client supports. For more information on these options, visit the [PubSub documentation](https://googleapis.dev/nodejs/pubsub/latest/global.html#ClientConfig).\n\nThe only required option in the configuration is a map of topic IDs to subscription IDs. To be consistent with how other message queue systems work, the topic ID is specified in the `EventPattern` decorator. For PubSub, we also need the subscription ID. This can be specified in the `topics` field of the configuration object.\n\n```typescript\nconst app = await NestFactory.createMicroservice(AppModule, {\n  strategy: new PubSubServer({\n    topics: {\n      'my-topic': {\n        subscriptionId: 'my-subscription'\n      }\n    }\n  })\n});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrallen%2Fnestjs-google-pubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrallen%2Fnestjs-google-pubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrallen%2Fnestjs-google-pubsub/lists"}