3.0.2 • Published 5 years ago

@superbalist/js-pubsub-google-cloud v3.0.2

Weekly downloads
10
License
MIT
Repository
github
Last release
5 years ago

@superbalist/js-pubsub-google-cloud

A Google Cloud adapter for the js-pubsub package.

Author Build Status Software License NPM Version NPM Downloads

Installation

npm install @superbalist/js-pubsub-google-cloud

Usage

"use strict";

let pubsub = require('@google-cloud/pubsub');
let GoogleCloudPubSubAdapter = require('@superbalist/js-pubsub-google-cloud');

process.env.GOOGLE_APPLICATION_CREDENTIALS = '/path/to/your-gcloud-key.json';

let client = pubsub({
  projectId: 'your-project-id-here'
});

let adapter = new GoogleCloudPubSubAdapter(client);

// disable auto topic & subscription creation
adapter.autoCreateTopics = false; // this is true by default
adapter.autoCreateSubscriptions = false; // this is true by default

// set a unique client identifier for the subscriber
adapter.clientIdentifier = 'search_service';

// consume messages
// note: this is a blocking call
adapter.subscribe('my_channel', (message) => {
  console.log(message);
  console.log(typeof message);
});

// publish messages
adapter.publish('my_channel', {first_name: 'Matthew'});
adapter.publish('my_channel', 'Hello World');

// publish multiple messages
let messages = [
  'message 1',
  'message 2',
];
adapter.publishBatch('my_channel', messages);

Examples

The library comes with examples for the adapter and a Dockerfile for running the example scripts.

Run make up.

You will start at a bash prompt in the /usr/src/app directory.

If you need another shell to publish a message to a blocking consumer, you can run docker-compose run js-pubsub-google-cloud /bin/bash

To run the examples:

$ node examples/GoogleCloudConsumerExample.js
$ node examples/GoogleCloudPublishExample.js (in a separate shell)
3.0.2

5 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.1

7 years ago