https://github.com/cognitev/pubsub-gcp-js
a wrapping package around GCP pubsub package to provide a more convenient, abstract functionalities
https://github.com/cognitev/pubsub-gcp-js
events gcp javascript nodejs pubsub
Last synced: about 1 month ago
JSON representation
a wrapping package around GCP pubsub package to provide a more convenient, abstract functionalities
- Host: GitHub
- URL: https://github.com/cognitev/pubsub-gcp-js
- Owner: cognitev
- License: agpl-3.0
- Created: 2020-06-17T14:47:06.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-02T22:07:46.000Z (about 4 years ago)
- Last Synced: 2025-02-09T23:18:01.161Z (over 1 year ago)
- Topics: events, gcp, javascript, nodejs, pubsub
- Language: JavaScript
- Size: 152 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pubsub-gcp-js
[](https://www.gnu.org/licenses/agpl-3.0)
[](https://github.com/cognitev/pubsub-gcp-js/actions)
Wrapping package around gcp pubsub package to provide a more conveniet, abstract functionalities
## how to install
```shell
npm i --save pubsub-gcp
```
## how to use
- first step is to initialize pubsub client with your account credentialis
```js
const pubsub = require('pubsub-gcp');
const privateKey = 'gcp_private_key';
const email = 'account_email';
const projectId = 'target_gcp_project';
await pubsub.initClient(projectId, email, privateKey);
```
here you have 3 params that you get from your account on GCP to authorize the package
to publish messages on your behalf.
Note: if you pass any of those params as `null` or did not pass any of them at all, they will replaced by the
following envs respectively:
- `GCLOUD_PROJECT_ID_PUBSUB`
- `GCLOUD_CLIENT_EMAIL`
- `GCLOUD_PRIVATE_KEY`
- to publish a message on any of your topics:
```js
await pubsub.publish({'random': 'message'}, 't2'); // will return message id on topic
```
Note: you can pass a third argument `create_topic` as true to auto create the topic then publish the message