2.1.1 • Published 2 years ago

pubsub-node v2.1.1

Weekly downloads
8
License
ISC
Repository
-
Last release
2 years ago

pubsub-node

Simple plugin that makes interacting with pubsub easier

Install

npm install --save pubsub-node

Instructions

FlowControl.maxmessages doesn't take numbers below 10 into account

To enable subscription error handling and logging pass initiated "stackdriver-logging-node"-logger to the require function

BREAKING!

subscription options are given separately to each subscription from 1.5.0 forward. (example below)

Requires NodeJS >= 8.13.0 from 1.6.0 forward

run tests with, tests require running pubsub emulator locally and guiding pubsub to use it with env variable "PUBSUB_EMULATOR_HOST=localhost:8085" npm test

Example

import pubSubNode, {Message, CreateSubscriptionOptions} from 'pubsub-node';
import {createGenericLogger, init} from 'stackdriver-logging-node';
init('test-project', false, 'info');

const logger = createGenericLogger({route: 'pubsub-node'});

const options: CreateSubscriptionOptions = {
  flowControl: {
    maxMessages: 10,
  }
}

function logError(error: any) {
  logger.error('Error in pubsub subscription', error);
}

function wait(): Promise<void> {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve();
    }, 10000);
  });
}

function messageHandler(message: Message) {
  let data = JSON.parse(message.data.toString());
  logger.info('received message', data, message.attributes);
  message.ack();
}

async function test(): Promise<void> {  
  pubSubNode.initialize({}, logError);
  await pubSubNode.createTopics(['test-topic', 'test-topic2']);
  await pubSubNode.subscription('test-topic', 'test-topic-subscription', messageHandler, options); 
  await pubSubNode.publish('test-topic', {status: 'ok'}, {origin: 'test-project'});
  await wait();
}

test();

export default test;
2.1.1

2 years ago

2.1.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.0

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago