add options in broker
This commit is contained in:
parent
47497b49b3
commit
c3cabc1fe5
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,6 +1,8 @@
|
||||
# Develop tools
|
||||
/.vscode/
|
||||
/.idea/
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
@ -13,6 +15,7 @@
|
||||
_obj
|
||||
_test
|
||||
_build
|
||||
.DS_Store
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
|
@ -4,6 +4,7 @@ package broker // import "go.unistack.org/micro/v4/broker"
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"go.unistack.org/micro/v4/metadata"
|
||||
"go.unistack.org/micro/v4/options"
|
||||
@ -19,6 +20,8 @@ var (
|
||||
ErrDisconnected = errors.New("broker disconnected")
|
||||
// ErrInvalidMessage returns when message has nvalid format
|
||||
ErrInvalidMessage = errors.New("broker message has invalid format")
|
||||
// DefaultGracefulTimeout
|
||||
DefaultGracefulTimeout = 5 * time.Second
|
||||
)
|
||||
|
||||
// Broker is an interface used for asynchronous messaging.
|
||||
|
@ -3,6 +3,7 @@ package broker
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.unistack.org/micro/v4/codec"
|
||||
@ -36,22 +37,27 @@ type Options struct {
|
||||
Name string
|
||||
// Address holds the broker address
|
||||
Address []string
|
||||
|
||||
Wait *sync.WaitGroup
|
||||
|
||||
GracefulTimeout time.Duration
|
||||
}
|
||||
|
||||
// NewOptions create new Options
|
||||
func NewOptions(opts ...options.Option) Options {
|
||||
options := Options{
|
||||
newOpts := Options{
|
||||
Register: register.DefaultRegister,
|
||||
Logger: logger.DefaultLogger,
|
||||
Context: context.Background(),
|
||||
Meter: meter.DefaultMeter,
|
||||
Codecs: make(map[string]codec.Codec),
|
||||
Tracer: tracer.DefaultTracer,
|
||||
GracefulTimeout: DefaultGracefulTimeout,
|
||||
}
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
o(&newOpts)
|
||||
}
|
||||
return options
|
||||
return newOpts
|
||||
}
|
||||
|
||||
// PublishOptions struct
|
||||
|
Loading…
Reference in New Issue
Block a user