mirror of
https://github.com/oarkflow/mq.git
synced 2025-10-06 16:36:53 +08:00
update: HTTP API
This commit is contained in:
32
options.go
32
options.go
@@ -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) {
|
||||
|
Reference in New Issue
Block a user