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 · 39 天前 · 878 次点击
    这是一个创建于 39 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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  
       39 天前
    可以控制队列的优先级,也就变相的控制了某个队列的并发数:

    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
       39 天前
    awanganddong
        3
    awanganddong  
    OP
       38 天前   ❤️ 1
    找到解决方案了,可以再重新起一个 server

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