Last active
November 8, 2017 18:04
-
-
Save carlozamagni/62b2470740e0d888bdc41d54e86d6c26 to your computer and use it in GitHub Desktop.
Log a pubsub topic to console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const PubSub = require('@google-cloud/pubsub') | |
const pubSubClient = PubSub({ | |
projectId: '<project-id>', | |
keyFilename: 'service_account_test.json' | |
}) | |
var topic = pubSubClient.topic('<topic-name>'); | |
//topic.subscribe('newMessages', function(err, subscription, apiResponse) {}); | |
topic.subscription('message-logger').get({ autoCreate: true }, (err, subscription, apiResponse) => { | |
if (err) { | |
console.error(err) | |
return done() | |
} | |
let subscriptionName = subscription.name.split('/')[subscription.name.split('/').length - 1] | |
console.log('\n- subscription found:', subscriptionName) | |
console.log('- listing incoming messages:') | |
subscription.on('message', (msg) => { | |
console.log('received', msg) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment