google-app-engine - 如何以编程方式配置云任务队列
问题描述
开发人员感谢您提出这个问题,我希望您能帮助我摆脱这种情况。
我是谷歌云服务的新手,我正在学习云任务,我必须以编程方式创建队列并添加一些参数,如处理速率、存储桶大小。到目前为止,我无法找到任何解决方案。
我正在通过以下方式创建队列
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
}
如何添加处理速率、存储桶大小和最大并发速率等参数
解决方案
例如,您需要将此属性“rateLimits”添加到“队列”属性中
queue: {
name:client.queuePath(project,location,queue),
appEngineHttpQueue:{
appEngineRoutingOverride:{
service:default
},
rateLimits:{
maxDispatchesPerSecond:500
},
retryConfig:{
maxAttempts:1
}
}
请记住,属性“max_burst_size”等于“bucket_size”
推荐阅读
- perl - PlasmidSeeker,Perl 脚本因“权限被拒绝”错误而无法运行
- python - 为什么我无法从 docker 中运行的 python 服务器得到正确的回复?
- delphi - Delphi:使用 BobJenkinsHash 生成 TObject 的哈希/校验和
- linux - 当 while/if/etc 出现错误时如何使 bash 脚本失败?
- php - SQLSTATE[23000]:违反完整性约束:密钥 qr_codes_encoded_key_unique 的重复条目“B”
- javascript - 如何拆分int每两位并插入数组
- sql-server - 我想用盐对这个密码进行哈希处理,但它没有给我相同的答案,我直接对其进行哈希处理
- angular - 有没有可能根据以下情况在 *ngFor 上应用动态 css?
- bash - Bash script variable not being passed via ssh
- c# - NavigationView SetCheckedItem 不会触发 OnNavigationItemSelected