如何使用PubSub一次获取一条消息

时间:2018-07-30 18:27:34

标签: firebase google-cloud-pubsub firebase-queue

我需要我的onPublish方法(firebase端),一次只能收到一条消息。

我的代码是这样的:

Google Cloud(AppEngine):

    var functions = require('firebase-functions');

    module.exports =
      functions.pubsub.topic('user_assigner').onPublish((event) => { 
          return someAsyncCode() //return promise;
      });

Firebase

$data = array("accountId" => $accountId, 
    "emailSubject" => "Your Zurich Application",
    "templateId" => $templateId, 
    "templateRoles" => array(['name'     => $recipientName,
     'email'    => $toemail,
     'roleName' => $templateRoleName],
    ['name'     => $recipientName2,
     'email'    => $toemail2,
     'roleName' => $templateRoleName2]),

            "tabs" => array( "textTabs" => array ( array (
                                    "tabLabel" => "fname",
                                    "value" => $fullname),
                                    array (
                                    "tabLabel" => "b_fname",
                                    "value" => $fullname2),
                                    array (
                                    "tabLabel" => "Text c7685472-b0d8-4865-a4e5-07ee83bc782f",
                                    "value" => $accountname),
                                    array (
                                    "tabLabel" => "Text 61c6e382-5b88-4f09-82df-74199424d608",
                                    "value" => $accountadd1),
                                    array (
                                    "tabLabel" => "Text b3aaeee9-15f9-4e14-9682-7338f4182124",
                                    "value" => $accountadd2),
                                    array (
                                    "tabLabel" => "Text 817aabd0-613b-4c50-8c4f-40837bfb3de7",
                                    "value" => $county),
                                    array (
                                    "tabLabel" => "dob1",
                                    "value" => $dob1),
                                    array (
                                    "tabLabel" => "dob2",
                                    "value" => $dob2),
                                    array (
                                    "tabLabel" => "mp",
                                    "value" => $mp),
                                    array (
                                    "tabLabel" => "li",
                                    "value" => $li),
                                    array (
                                    "tabLabel" => "marketing",
                                    "value" => $marketing),
                                    array (
                                    "tabLabel" => "switchyes",
                                    "value" => $switchyes),
                                    array (
                                    "tabLabel" => "switchno",
                                    "value" => $switchno),
                                    array (
                                    "tabLabel" => "iban",
                                    "value" => $iban),
                                    array (
                                    "tabLabel" => "bic",
                                    "value" => $bic),


)),
    "status" => "sent");             

我需要代码someAsyncCode来逐个运行消息,有没有办法做到这一点? 我在documentation of the publisher上看到了maxMessages批处理,但我认为这是设置发布者将新消息推送到消息队列时的限制。因此,如果我将服装设置为相同,发布者将推动一个购买对象(gcloud端),而onPublish(firebase端)将获得所有消息,而不管它是否正在处理一个。

0 个答案:

没有答案