pubsub-node v2.1.1
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 years ago
2 years ago
2 years ago
2 years ago
2 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago