如何从Firebase Cloud功能在Google Pub / Sub中发布消息?

时间:2018-01-13 14:30:21

标签: javascript publish-subscribe google-cloud-functions google-cloud-pubsub

我编写了一个接收http请求并发送电子邮件的函数。但我想发送消息pubsub,但在文档中的示例只显示触发的pubsub请求,并且没有主机,端口,id,代理的passwd等信息。我想收到一个http请求并向移动设备发送一条发布消息,我认为这是mqtt。

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)
})
})

1 个答案:

答案 0 :(得分:8)

据我了解,您希望从Firebase云功能实施中向Pub / Sub发送消息。

您可以轻松使用已定义功能的Node.js Pub/Sub client library,例如publish

或者,如果您愿意,可以构建自己的客户端,直接调用REST API for Google Cloud Pub/Sub。如果它更适合您的需求,还有RPC reference

你不需要

  

代理的主机,端口,id,passwd等信息

作为上述客户端,或者您的REST API请求将需要authentication

相关问题