【发布时间】:2015-11-09 23:58:48
【问题描述】:
我正在尝试将 pushEndpoint 添加到我尝试在 Google 的 PubSub (https://cloud.google.com/pubsub/) 中创建的订阅中,以便能够接收来自 Gmail 的推送更新。我要添加的 pushEndpoint 是带有端口的 HTTPS-URL(例如:https://developers.example.com:9081/pushEndpoint),但我不断收到Invalid push endpoint given (endpoint=https://developers.briteback.com:9081/mailSyncHandler). Refer to https://cloud.google.com/pubsub/subscriber#create for more information.
所以问题是是否可以将端口添加到 pushEndpoint?
这是尝试创建订阅的代码:
var rp = require('request-promise');
rp({
url: 'https://pubsub.googleapis.com/v1/projects/projectId/subscriptions/mailSync',
method: 'PUT',
headers: {
Authorization: 'Bearer accessToken'
},
json: {
topic: 'projects/projectId/topics/mailSync',
pushConfig: {
pushEndpoint: 'https://developers.example.com:9081/mailSyncHandler'
}
}
})
.then(function(response) {
console.log(response);
res.send(response);
})
.catch(function(err) {
console.error(err);
res.status(err.statusCode).send(err.error.error.message);
});
【问题讨论】:
-
请尝试从 API 资源管理器添加您的推送订阅,并让我们知道它是否适用于指定的端口。链接:developers.google.com/apis-explorer/#search/…
-
同样的事情发生在 API 资源管理器中。错误消息:
Invalid push endpoint given (endpoint=https://developers.example.com:8091/mailSyncHandler). Refer to https://cloud.google.com/pubsub/subscriber#create for more information.。状态:INVALID_ARGUMENT -
因此从这个小实验中可以清楚地看出 pubsub 不支持带有端口号的推送端点。尝试某种方式在您的推送端点上重新路由以将消息从发布订阅转发到您想要的端口。
-
认为 =) 使用 node-http-proxy 创建了一个简单的反向代理,以使其与我们的设置配合使用
-
(Psst..你没有清理所有的 URL,如果重要的话)
标签: javascript node.js gmail-api google-cloud-pubsub