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

2024 年 3 月 19 日
 awanganddong

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)
	}

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

1581 次点击
所在节点    Go 编程语言
5 条回复
qloog
2024 年 3 月 19 日
可以控制队列的优先级,也就变相的控制了某个队列的并发数:

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
2024 年 3 月 19 日
awanganddong
2024 年 3 月 20 日
找到解决方案了,可以再重新起一个 server

然后记得指定就可以了
client.Enqueue(task1, asynq.Queue("notifications"))
qloog
2024 年 4 月 2 日
这个 server 专门跑 notifications 队列?
awanganddong
2024 年 4 月 6 日
不是,是一些牵扯到扣费的逻辑,为了保证用户余额的一致性,然后串行扣费。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://study.congcong.us/t/1024954

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX