首页 > 解决方案 > 如何以编程方式配置云任务队列

问题描述

开发人员感谢您提出这个问题,我希望您能帮助我摆脱这种情况。

我是谷歌云服务的新手,我正在学习云任务,我必须以编程方式创建队列并添加一些参数,如处理速率、存储桶大小。到目前为止,我无法找到任何解决方案。

我正在通过以下方式创建队列

const createQueue = async (
    queueName: string
) => {
    const project = 'projectname'; // Your GCP Project id
    const queue = queueName; // Name of the Queue to create
    const location = 'location name' // The GCP region in which to create the queue
    const {
        v2beta3
    } = require('@google-cloud/tasks');
    const client = new v2beta3.CloudTasksClient();

    try {
        const [response] = await client.createQueue({
            parent: client.locationPath(project, location),
            queue: {
                name: client.queuePath(project, location, queue),
                appEngineHttpQueue: {
                    appEngineRoutingOverride: {
                        service: 'default'
                    }
                },
            },
        });
        console.log(`Created queue ${response.name}`);
        return response.name;
    } catch (error) {
        console.error(Error(error.message));
    }
    // return null
}

如何添加处理速率、存储桶大小和最大并发速率等参数

标签: google-app-enginegoogle-cloud-platformgoogle-cloud-tasks

解决方案


例如,您需要将此属性“rateLimits”添加到“队列”属性中

queue: {
   name:client.queuePath(project,location,queue),
   appEngineHttpQueue:{
      appEngineRoutingOverride:{
         service:default
      },
      rateLimits:{
         maxDispatchesPerSecond:500
      },
      retryConfig:{
         maxAttempts:1
      }
   }

请记住,属性“max_burst_size”等于“bucket_size”


推荐阅读