mirror of
https://github.com/oarkflow/mq.git
synced 2025-10-05 16:06:55 +08:00
feat: separate broker
This commit is contained in:
30
queue.go
Normal file
30
queue.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package mq
|
||||
|
||||
import (
|
||||
"github.com/oarkflow/xsync"
|
||||
)
|
||||
|
||||
type Queue struct {
|
||||
name string
|
||||
consumers xsync.IMap[string, *consumer]
|
||||
tasks chan *QueuedTask // channel to hold tasks
|
||||
}
|
||||
|
||||
func newQueue(name string, queueSize int) *Queue {
|
||||
return &Queue{
|
||||
name: name,
|
||||
consumers: xsync.NewMap[string, *consumer](),
|
||||
tasks: make(chan *QueuedTask, queueSize), // buffer size for tasks
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Broker) NewQueue(qName string) *Queue {
|
||||
q, ok := b.queues.Get(qName)
|
||||
if ok {
|
||||
return q
|
||||
}
|
||||
q = newQueue(qName, b.opts.queueSize)
|
||||
b.queues.Set(qName, q)
|
||||
go b.dispatchWorker(q)
|
||||
return q
|
||||
}
|
Reference in New Issue
Block a user