feat: separate broker

This commit is contained in:
Oarkflow
2024-10-05 18:34:24 +05:45
parent 324c6f691e
commit 40f5d0dad3
18 changed files with 508 additions and 1593 deletions

30
queue.go Normal file
View 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
}