V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
awanganddong

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

  •  
  •   awanganddong · Mar 19, 2024 · 1606 views
    This topic created in 771 days ago, the information mentioned may be changed or developed.

    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 replies    2024-04-06 13:45:19 +08:00
    qloog
        1
    qloog  
       Mar 19, 2024
    可以控制队列的优先级,也就变相的控制了某个队列的并发数:

    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
       Mar 19, 2024
    awanganddong
        3
    awanganddong  
    OP
       Mar 20, 2024   ❤️ 1
    找到解决方案了,可以再重新起一个 server

    然后记得指定就可以了
    client.Enqueue(task1, asynq.Queue("notifications"))
    qloog
        4
    qloog  
       Apr 2, 2024
    这个 server 专门跑 notifications 队列?
    awanganddong
        5
    awanganddong  
    OP
       Apr 6, 2024
    不是,是一些牵扯到扣费的逻辑,为了保证用户余额的一致性,然后串行扣费。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3782 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 10:30 · PVG 18:30 · LAX 03:30 · JFK 06:30
    ♥ Do have faith in what you're doing.