pubsub-plus-emulator
v1.0.5
Published
Google cloud pub/sub plus emulator for local testing
Downloads
7
Maintainers
Readme
Pubsub Plus Emulator
This is a wrapper for google cloud pub/sub and local testing emulator
Install
npm
$ npm install pubsub-plus-emulator
Using Google Cloud Pubsub locally with Google Cloud Emulator
$ docker run -it -p 8085:8085 knarz/pubsub-emulator
Using Pubsub on staging with google cloud emulator
- Put the google cloud pubsub service account json file into the root directory of the project
- rename the service account json file to
staging-service-account.json
Using Pubsub on staging with google cloud emulator
- Put the google cloud pubsub service account json file into the root directory of the project
- rename the service account json file to
production-service-account.json
Usage
The library is imported in either of the following ways:
import PubSub from 'pubsub-plus-emulator';
To publish a message
import PubSub from "pubsub-plus-emulator";
process.env.NODE_ENV = "development";
export const publisher = async (payload) => {
const pubsubClient = new PubSub();
await pubsubClient.publish("topicName", payload);
};
publisher(payload)
const payload = {
firstName: "Ropo",
lastName: "Olatujoye",
twitter: "@iamfiropo",
};
To subscribe to an event
import PubSub from 'pubsub-plus-emulator';
const pubsubClient = new PubSub();
pubsubClient.subscribe('topicName', 'subscriptionName', subscriberFunc);
Note: It's important this is an arrow function
const subscriberFunc = (data) => {
console.log(data);
// do anything with the received event
}