{"id":28436095,"url":"https://github.com/nestjstools/messaging-google-pubsub-extension","last_synced_at":"2026-03-03T22:31:07.494Z","repository":{"id":293076081,"uuid":"982870071","full_name":"nestjstools/messaging-google-pubsub-extension","owner":"nestjstools","description":"Extension for @nestjstools/messaging to handle and dispatch messages over Google pubsub protocol","archived":false,"fork":false,"pushed_at":"2025-10-19T17:41:04.000Z","size":246,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-20T21:22:00.320Z","etag":null,"topics":["google-pubsub","messaging","nestjs","nestjs-pubsub","nodejs","service-bus"],"latest_commit_sha":null,"homepage":"https://nestjstools.gitbook.io/nestjstools-messaging-docs","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/nestjstools.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-13T14:24:32.000Z","updated_at":"2025-10-19T17:40:10.000Z","dependencies_parsed_at":"2025-05-30T21:14:52.121Z","dependency_job_id":"e5df8ce2-0b0e-48f1-82fd-7707ff149042","html_url":"https://github.com/nestjstools/messaging-google-pubsub-extension","commit_stats":null,"previous_names":["nestjstools/messaging-google-pubsub-extension"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/nestjstools/messaging-google-pubsub-extension","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjstools%2Fmessaging-google-pubsub-extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjstools%2Fmessaging-google-pubsub-extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjstools%2Fmessaging-google-pubsub-extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjstools%2Fmessaging-google-pubsub-extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nestjstools","download_url":"https://codeload.github.com/nestjstools/messaging-google-pubsub-extension/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjstools%2Fmessaging-google-pubsub-extension/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30064277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","messaging","nestjs","nestjs-pubsub","nodejs","service-bus"],"created_at":"2025-06-05T21:10:03.938Z","updated_at":"2026-03-03T22:31:07.466Z","avatar_url":"https://github.com/nestjstools.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimage src=\"nestjstools-logo.png\" width=\"400\"\u003e\n\u003c/p\u003e\n\n# NestJS Google Cloud Pub/Sub Messaging Extension – Event-Driven Transport for Distributed Systems\n\n### This extension allows you to use **Google Cloud Pub/Sub as a message bus channel**.\n\nA Google Cloud Pub/Sub transport adapter for the **NestJSTools Messaging Library**, enabling scalable, event-driven and distributed architectures in NestJS applications.\n\nDesigned for:\n\n* Google Cloud microservices\n* Event-driven systems\n* CQRS architectures\n* Cross-language messaging\n* Distributed platforms running on GCP\n\n---\n\n## Documentation\n\n* https://docs.nestjstools.com/messaging\n* https://nestjstools.com\n\n---\n\n## Installation\n\n```bash\nnpm install @nestjstools/messaging @nestjstools/messaging-google-pubsub-extension \n```\n\nor\n\n```bash\nyarn add @nestjstools/messaging @nestjstools/messaging-google-pubsub-extension\n```\n## Google PubSub Integration: Messaging Configuration Example\n\n---\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { MessagingModule } from '@nestjstools/messaging';\nimport { SendMessageHandler } from './handlers/send-message.handler';\nimport { MessagingGooglePubSubExtensionModule, GooglePubSubChannelConfig } from '@nestjstools/messaging-google-pubsub-extension';\n\n@Module({\n  imports: [\n    MessagingGooglePubSubExtensionModule, // Importing the GooglePubSub extension module\n    MessagingModule.forRoot({\n      buses: [\n        {\n          name: 'message.bus',\n          channels: ['pubsub-command'],\n        },\n      ],\n      channels: [\n        new GooglePubSubChannelConfig({\n          name: 'pubsub-command',\n          enableConsumer: true, // Enable if you want to consume messages\n          autoCreate: true, // Auto-create queue if it doesn't exist\n          credentials: { // Optional\n            projectId: 'x',\n          },\n          topicName: 'eventTopic',\n          subscriptionName: 'eventSubscriptionTopic',\n        }),\n      ],\n      debug: true, // Optional: Enable debugging for Messaging operations\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n## Dispatch messages via bus (example)\n\n```typescript\nimport { Controller, Get } from '@nestjs/common';\nimport { CreateUser } from './application/command/create-user';\nimport { IMessageBus, MessageBus, RoutingMessage } from '@nestjstools/messaging';\n\n@Controller()\nexport class AppController {\n  constructor(\n    @MessageBus('message.bus') private pubsubMessageBus: IMessageBus,\n  ) {}\n\n  @Get('/pubsub')\n  createUser(): string {\n    this.pubsubMessageBus.dispatch(new RoutingMessage(new CreateUser('John FROM pubsub'), 'my_app_command.create_user'));\n\n    return 'Message sent';\n  }\n}\n```\n\n### Handler for your message\n\n```typescript\nimport { CreateUser } from '../create-user';\nimport { IMessageBus, IMessageHandler, MessageBus, MessageHandler, RoutingMessage, DenormalizeMessage } from '@nestjstools/messaging';\n\n@MessageHandler('my_app_command.create_user')\nexport class CreateUserHandler implements IMessageHandler\u003cCreateUser\u003e{\n\n  handle(message: CreateUser): Promise\u003cvoid\u003e {\n    console.log(message);\n    // TODO Logic there\n  }\n}\n```\n\n---\n\n### Key Features:\n\n* **Google Cloud Pub/Sub Integration** Seamlessly send and receive messages using Google Cloud Pub/Sub within your NestJS application.\n\n* **Local Development Support with Emulator** Supports running against the Google Pub/Sub emulator for local development and testing (via PUBSUB_EMULATOR_HOST).\n\n* **Automatic Topic and Subscription Creation** Automatically creates Pub/Sub topics and subscriptions when autoCreate: true is set in the configuration.\n\n* **Named Buses \u0026 Channel Routing** Supports custom-named message buses and routing of messages across multiple channels for event-driven architecture.\n\n* Easily configure projectId, topicName, and subscriptionName for full control over Pub/Sub setup.\n---\n\n## 📨 Communicating Beyond a NestJS Application (Cross-Language Messaging)\n\n### To enable communication with a Handler from services written in other languages, follow these steps:\n\n1. **Publish a Message to the Topic**\n\n2. **Include the Routing Key Header**\n   Your message **must** include a header attribute named `messaging-routing-key`.\n   The value should correspond to the routing key defined in your NestJS message handler:\n\n   ```ts\n   @MessageHandler('my_app_command.create_user') // \u003c-- Use this value as the routing key\n   ```\n\n---\n## 🔧 Send additional attributes into your message\n\n   ```ts\n    this.pubSubMessageBus.dispatch(new RoutingMessage(new CreateUser('id'), 'my_app_command.create_user', new GooglePubSubMessageOptions({YourAttribute: 'value'})));\n   ```\n---\n\n## Configuration options\n\n### GooglePubSubChannel\n\n#### **GooglePubSubChannelConfig**\n\n| **Property**           | **Description**                                                                                  | **Default Value** |\n| ---------------------- | ------------------------------------------------------------------------------------------------ | ----------------- |\n| **`name`**             | The name of the messaging channel within your app (used for internal routing).                   |                   |\n| **`credentials`**      | Google Cloud Pub/Sub credentials (e.g., `{ projectId: 'my-project' }`).                          |                   |\n| **`enableConsumer`**   | Whether to enable message consumption (i.e., subscribing and processing messages from Pub/Sub).  | `true`            |\n| **`autoCreate`**       | Automatically create the topic and subscription if they do not exist in the Pub/Sub environment. | `true`            |\n| **`topicName`**        | The name of the Google Pub/Sub topic to publish messages to.                                     |                   |\n| **`subscriptionName`** | The name of the subscription used to consume messages from the topic.                            |                   |\n\n---\n\n## Real world working example with RabbitMQ \u0026 Redis - but might be helpful to understand how it works\nhttps://github.com/nestjstools/messaging-rabbitmq-example\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnestjstools%2Fmessaging-google-pubsub-extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnestjstools%2Fmessaging-google-pubsub-extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnestjstools%2Fmessaging-google-pubsub-extension/lists"}