我编写了一个函数来接收 http 请求并发送电子邮件。但是,我想接收一个 http 请求并发送一个 pub 消息。问题是文档不清楚。我该怎么做?
这是我的实际代码。
exports.weeklyEmail = functions.https.onRequest((req,res) => {
const email = '****@gmail.com'
console.log('Sending e-mail')
const mailOptions = {
to: email,
from: '****@alunos.utfpr.edu.br',
subject: 'Teste',
text: 'Conteudo do email '
}
mailTransport.sendMail(mailOptions).then(
() => {
res.send('Email sent')
}
).catch(error => {
res.send(error)
})
})
最佳答案
据我了解,您希望从您的 Firebase Cloud Functions 实现向 Pub/Sub 发送消息。
您可以轻松使用 Node.js Pub/Sub client library ,具有已经定义的功能,例如 publish .
或者,如果您愿意,可以构建自己的客户端,直接调用 REST API for Google Cloud Pub/Sub .还有一个 RPC reference如果它更适合您的需求。
你不需要
information like host, port, id, passwd of broker
作为提到的客户端,或者您的 REST API 请求将需要 authentication .
关于javascript - 如何从 Firebase Cloud Function 在 Google Pub/Sub 中发布消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48240813/