update: HTTP API

This commit is contained in:
Oarkflow
2025-03-30 16:55:32 +05:45
parent ba75adc7d6
commit 31a9fb8ba7
11 changed files with 340 additions and 85 deletions

View File

@@ -2,10 +2,12 @@ package mq
import (
"context"
"fmt"
"runtime"
"time"
"github.com/oarkflow/mq/logger"
"github.com/oarkflow/mq/utils"
)
type ThresholdConfig struct {
@@ -57,12 +59,6 @@ func WithBatchSize(batchSize int) PoolOption {
}
}
func WithHealthServicePort(port int) PoolOption {
return func(p *Pool) {
p.port = port
}
}
func WithHandler(handler Handler) PoolOption {
return func(p *Pool) {
p.handler = handler
@@ -117,9 +113,22 @@ func WithPlugin(plugin Plugin) PoolOption {
}
}
var BrokerAddr string
func init() {
if BrokerAddr == "" {
port, err := utils.GetRandomPort()
if err != nil {
BrokerAddr = ":8081"
} else {
BrokerAddr = fmt.Sprintf(":%d", port)
}
}
}
func defaultOptions() *Options {
return &Options{
brokerAddr: ":8081",
brokerAddr: BrokerAddr,
maxRetries: 5,
respondPendingResult: true,
initialDelay: 2 * time.Second,
@@ -130,8 +139,6 @@ func defaultOptions() *Options {
maxMemoryLoad: 5000000,
storage: NewMemoryTaskStorage(10 * time.Minute),
logger: logger.NewDefaultLogger(),
BrokerRateLimiter: NewRateLimiter(10, 5),
ConsumerRateLimiter: NewRateLimiter(10, 5),
}
}
@@ -194,6 +201,13 @@ func WithTLS(enableTLS bool, certPath, keyPath string) Option {
}
}
// WithHTTPApi - Option to enable/disable TLS
func WithHTTPApi(flag bool) Option {
return func(o *Options) {
o.enableHTTPApi = flag
}
}
// WithCAPath - Option to enable/disable TLS
func WithCAPath(caPath string) Option {
return func(o *Options) {