Google Cloud Pub / Sub和后台功能调用出现问题

Ili*_*s M 5 go google-cloud-platform google-cloud-pubsub google-cloud-functions

我正在为一个项目使用一些Google云解决方案:

  • Google App引擎(Go 1.11)
  • Google云功能(Go 1.11)
  • Google cloud Pub / Sub(主题名称:workers)

我的App Engine项目只是关于将消息发布到主题“工人”。

当发布/订阅收到有关“工人”主题的消息时,应触发My Cloud功能。

在运行了一些密集的负载测试之后,我可以看到不是我的所有工作程序都被调用了。

该测试将每15秒抛出200条消息,最后达到总共10万条已发布消息(应该是相同数量的函数调用)。

将消息发送到该主题没有问题,但是当我查看Google Stackdriver Metrics资源管理器(基于云功能的执行状态的指标)时,我发现缺少一些工作程序调用。

发布消息的App Engine代码:

func PublishMessage(task *models.Task) error {
    if task == nil {
       return errors.New("Empty task")
    }

    pubSubTopic := GetPubSubClient().Topic("workers")
    ctx := context.Background()

    message, err := json.Marshal(task); if err != nil {
        return err
    }

    result := pubSubTopic.Publish(ctx, &pubsub.Message{
        Data: message,
    })

    id, err := result.Get(ctx)
    if err != nil {
        return err
    }

    log.Printf("Published a message; msg ID: %v\n", id)

    return nil
}
Run Code Online (Sandbox Code Playgroud)

这是我的Google云功能上的代码:

func Run(ctx context.Context, m PubSubMessage) error {

    task := &models.Task{}

    if err := json.Unmarshal(m.Data, task); err != nil {
        return err
    }

    log.Printf(*task.Name)

    return nil
}
Run Code Online (Sandbox Code Playgroud)

编辑1:

这是我部署云功能的方式:

gcloud functions deploy my_worker --runtime go111 --entry-point Run --trigger-topic workers

这是pub / sub的Metrics资源管理器:

发布/订阅指标

这是有关云函数调用计数的Metrics资源管理器: 云功能指标