我有以下代码:
exports = function(changeEvent) {
var {PubSub} = require("@google-cloud/pubsub");
var avro = require("avro-js");
const keyFilename = context.values.get("GOOGLE_APPLICATION_CREDENTIALS")
const projectId = "<project_name>"
const pubSubClient = new PubSub({projectId, keyFilename});
const topicName = "<topic_name>"
const topic = pubSubClient.topic(topicName);
try {
const data = "something";
const dataBuffer = Buffer.from(data);
return topic.publish(dataBuffer)
.then((messageId) => console.log(`Message ${messageId} published.`))
.catch((err) => console.log(`Error publishing message: ${err}`));
} catch(err) {
console.log("Error: ", err.message);
}
};
运行上述命令时,它返回以下内容:
Error publishing message: FunctionError: TypeError: 'createReadStream' is not a function
> result:
{
"$undefined": true
}
> result (JavaScript):
EJSON.parse('{"$undefined":true}')
需要指出的是:
- 我不是第一个遇到这个问题的人,但这两个帖子都没有得到太多关注
- The GOOGLE_APPLICATION_CREDENTIALS value ought to be a path to the secret called service-account.. it's a json of a service account key from GCP. What confuses me though is that if I console.log the path it prints out the secret as json and not the path to the secret
在这一点上,我不确定它能是什么.起初,我认为这可能是异步和同步的问题.但我try 了这两种方法,结果都出现了相同的错误.另一个问题可能是与客户端的身份验证.但是错误消息并没有为我提供太多信息,在搜索createReadStream
的时候,我找不到任何有用的东西.