如何从Firebase Cloud功能在Google Pub / Sub中发布消息? [英] How to publish message in Google Pub/Sub from Firebase Cloud Function?

查看:137
本文介绍了如何从Firebase Cloud功能在Google Pub / Sub中发布消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I write a function that receive a http request and send a e-mail. But I wants send a message pubsub, but in the documentation the examples showing only triggered pubsub requests and no have information like host, port, id, passwd of broker. I wants receive a http request and send a pub message, I think that is mqtt, to a mobile device.

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云功能实施中向Pub / Sub发送消息。

As I understand, you wish to send a message to Pub/Sub from your Firebase Cloud Functions implementation.

您可以轻松使用 Node.js Pub / Sub客户端库,已定义的功能,例如发布

You can easily use the Node.js Pub/Sub client library, with already defined functionalities, like publish.

或者,如果您愿意,可以建立自己的客户,直接致电 Google Cloud Pub / Sub的REST API 。如果它更适合您的需要,还有 RPC参考

Or, if you prefer, you can build your own client, directly calling the REST API for Google Cloud Pub/Sub. There's also a RPC reference if it suits your needs better.

您不需要


信息像主机,端口,id,passwd of broker

information like host, port, id, passwd of broker

作为上述客户端,或者你的REST API请求需要身份验证

as the mentioned client, or your REST API requests will require authentication .

这篇关于如何从Firebase Cloud功能在Google Pub / Sub中发布消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆