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

28
util.go Normal file
View File

@@ -0,0 +1,28 @@
package mq
import (
"context"
"encoding/json"
"github.com/oarkflow/mq/codec"
)
func (b *Broker) TLSConfig() TLSConfig {
return b.opts.tlsConfig
}
func (b *Broker) SyncMode() bool {
return b.opts.syncMode
}
func (b *Broker) HandleCallback(ctx context.Context, msg *codec.Message) {
if b.opts.callback != nil {
var result Result
err := json.Unmarshal(msg.Payload, &result)
if err == nil {
for _, callback := range b.opts.callback {
callback(ctx, result)
}
}
}
}