From 070ec53269a49f71bbd7278465ccda853b60a647 Mon Sep 17 00:00:00 2001 From: Pilwon Huh Date: Mon, 15 Dec 2014 12:32:32 -0500 Subject: [PATCH 1/2] Bug fix: pubsub does not publish message data. The official API documentation for `publish` endpoint requires `data` and `label` nested under `message` key. (see https://cloud.google.com/pubsub/v1beta1/topics/publish) ```json { "topic": string, "message": { "data": bytes, "label": [ { "key": string, "strValue": string, "numValue": long } ] } } ``` --- lib/pubsub/topic.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/pubsub/topic.js b/lib/pubsub/topic.js index 53ced5ac507..1e7d1d8997c 100644 --- a/lib/pubsub/topic.js +++ b/lib/pubsub/topic.js @@ -131,8 +131,11 @@ Topic.prototype.publishRaw = function(message, callback) { if (!util.is(message.data, 'string') && !util.is(message.data, 'buffer')) { message.data = new Buffer(JSON.stringify(message.data)).toString('base64'); } - message.topic = this.name; - this.makeReq_('POST', 'topics/publish', null, message, callback); + var body = { + message: message, + topic: this.name + }; + this.makeReq_('POST', 'topics/publish', null, body, callback); }; /** From f97cacacd5fd875e210ddca6ca330484b34e9eba Mon Sep 17 00:00:00 2001 From: Pilwon Huh Date: Mon, 15 Dec 2014 12:56:41 -0500 Subject: [PATCH 2/2] Updated test cases. --- test/pubsub/topic.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/pubsub/topic.js b/test/pubsub/topic.js index 800076b0a52..52514733626 100644 --- a/test/pubsub/topic.js +++ b/test/pubsub/topic.js @@ -150,7 +150,7 @@ describe('Topic', function() { it('should stringify non-strings & non-buffers', function(done) { topic.makeReq_ = function(method, path, qs, body) { - assert.deepEqual(body.data, messageObjDecoded); + assert.deepEqual(body.message.data, messageObjDecoded); done(); }; topic.publishRaw({ data: messageObj }, assert.ifError); @@ -160,7 +160,7 @@ describe('Topic', function() { topic.makeReq_ = function(method, path, qs, body) { assert.equal(method, 'POST'); assert.equal(path, 'topics/publish'); - assert.deepEqual(body.message, messageRaw.message); + assert.deepEqual(body.message.data, messageRaw.data); done(); }; topic.publishRaw(messageRaw, assert.ifError);