-
Notifications
You must be signed in to change notification settings - Fork 639
Description
Hi folks, as per the doc, the message objects provided to the subscription.on( 'message' ) listener/callback function don't contain the publishTime field:
// Register a listener for `message` events.
subscription.on('message', function(message) {
// Called every time a message is received.
// message.id = ID used to acknowledge its receival.
// message.data = Contents of the message.
// message.attributes = Attributes of the message.
});
IIUC PubSub doesn't guarantee message ordering, so having that timestamp in the messages would help with trying to buffer & order at the recipient end - but it's not there. From the comment it seems this was deliberately not included in the node.js client message implementation:
Simplify a message from an API response to have three properties, `id`,
`data` and `attributes`. `data` is always converted to a string.
Is this still desired? Might it make it in? Would a PR to include it be welcome, or is there a strong reason why it's not there?
Thanks!
Igor
Environment details
- OS: Tested on both OSX 10.11.6 and
alpine:latestinside Docker container running on OSX - Node.js version: v7.1.0 and v6.7.0 respectively
- npm version: 3.10.9 and 3.10.3 respectively
- google-cloud-node version: @google-cloud/pubsub@0.6.0 (via
npm install --save @google-cloud/pubsub) - Tested against local emulator and GCP PubSub instance
Steps to reproduce
- require
google-cloud/pubsub - create a topic
- subscribe to the topic
- publish a message to the topic
console.log( JSON.stringify( message ) );- message has no 'publishTime' field as per PubSub docs.
{"ackId":"projects/my-pubsub-test/subscriptions/sdfdsf234-1480376751660:262","id":"225","data":{"channel":"sdfdsf234","from":"58e73d48-29ea-4cd0-b46b-085fd1bf89dd","msg":"my message"},"attributes":{}}
I added console.log( msg ); on line 341 of node_modules/@google-cloud/pubsub/src/subscription.js to check the publishTime data is returned by PubSub, and it certainly seems to be:
{ ackId: 'projects/my-pubsub-test/subscriptions/sdfdsf234-1480376751660:262',
message:
{ data: 'eyJyb29tX25hbWUiOiJzZGZkc2YyMzQiLCJmcm9tIjoiNThlNzNkNDgtMjllYS00Y2QwLWI0NmItMDg1ZmQxYmY4OWRkIiwibXNnIjoibXkgbWVzc2FnZSJ9',
attributes: {},
messageId: '225',
publishTime: { seconds: '1480376756', nanos: 473000000 } } }
(NB when running against the emulator, the nanos field is always 0.)