V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
? http://golang.org/
? Go Playground
Go Projects
? Revel Web Framework
awanganddong
V2EX  ?  Go 编程语言

golang hibiken 这个消息队列怎么控制个 queue 的并发

  •  
  •   awanganddong · 41 天前 · 883 次点击
    这是一个创建于 41 天前的主题,其中的信息可能已经有所发展或是发生改变。

    腾讯云最新优惠活动来了:云产品限时1折,云服务器低至88元/年 ,点击这里立即抢购:9i0i.cn/qcloud,更有2860元代金券免费领取,付款直接抵现金用,点击这里立即领取:9i0i.cn/qcloudquan

    (福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

    https://github.com/hibiken/asynq

    看文档,

    	srv := asynq.NewServer(
    		asynq.RedisClientOpt{Addr: ":6379"},
    		asynq.Config{Concurrency: 20}, //并发控制
    	)
    
    	h := asynq.NewServeMux()
    	// ... Register handlers
    
    	// Run blocks and waits for os signal to terminate the program.
    	if err := srv.Run(h); err != nil {
    		log.Fatal(err)
    	}
    

    这个是对于整个项目的并发,现在只需要对于不同任务的并发控制,不知道怎么实现。

    5 条回复  ?  2024-04-06 13:45:19 +08:00
    qloog
        1
    qloog  
       41 天前
    可以控制队列的优先级,也就变相的控制了某个队列的并发数:

    srv := asynq.NewServer(
    asynq.RedisClientOpt{Addr: redisAddr},
    asynq.Config{
    // Specify how many concurrent workers to use
    Concurrency: 10,
    // Optionally specify multiple queues with different priority.
    Queues: map[string]int{
    "queue1": 6,
    "queue2": 3,
    "queue3": 1,
    },
    // See the godoc for other configuration options
    },
    )
    awanganddong
        2
    awanganddong  
    OP
       41 天前
    awanganddong
        3
    awanganddong  
    OP
       40 天前   ?? 1
    找到解决方案了,可以再重新起一个 server

    然后记得指定就可以了
    client.Enqueue(task1, asynq.Queue("notifications"))
    qloog
        4
    qloog  
       26 天前
    这个 server 专门跑 notifications 队列?
    awanganddong
        5
    awanganddong  
    OP
       23 天前
    不是,是一些牵扯到扣费的逻辑,为了保证用户余额的一致性,然后串行扣费。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5557 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 08:28 · PVG 16:28 · LAX 01:28 · JFK 04:28
    Developed with CodeLauncher
    ? Do have faith in what you're doing.


    http://www.vxiaotou.com