add options in broker #333

Merged
vtolstov merged 2 commits from devstigneev/micro:master into master 2024-04-08 23:17:50 +03:00
3 changed files with 21 additions and 9 deletions

3
.gitignore vendored
View File

@ -1,6 +1,8 @@
# Develop tools # Develop tools
/.vscode/ /.vscode/
/.idea/ /.idea/
.idea
.vscode
# Binaries for programs and plugins # Binaries for programs and plugins
*.exe *.exe
@ -13,6 +15,7 @@
_obj _obj
_test _test
_build _build
.DS_Store
# Architecture specific extensions/prefixes # Architecture specific extensions/prefixes
*.[568vq] *.[568vq]

View File

@ -4,6 +4,7 @@ package broker // import "go.unistack.org/micro/v4/broker"
import ( import (
"context" "context"
"errors" "errors"
"time"
"go.unistack.org/micro/v4/metadata" "go.unistack.org/micro/v4/metadata"
"go.unistack.org/micro/v4/options" "go.unistack.org/micro/v4/options"
@ -19,6 +20,8 @@ var (
ErrDisconnected = errors.New("broker disconnected") ErrDisconnected = errors.New("broker disconnected")
// ErrInvalidMessage returns when message has nvalid format // ErrInvalidMessage returns when message has nvalid format
ErrInvalidMessage = errors.New("broker message has invalid format") ErrInvalidMessage = errors.New("broker message has invalid format")
// DefaultGracefulTimeout
DefaultGracefulTimeout = 5 * time.Second
) )
// Broker is an interface used for asynchronous messaging. // Broker is an interface used for asynchronous messaging.

View File

@ -11,6 +11,7 @@ import (
"go.unistack.org/micro/v4/meter" "go.unistack.org/micro/v4/meter"
"go.unistack.org/micro/v4/options" "go.unistack.org/micro/v4/options"
"go.unistack.org/micro/v4/register" "go.unistack.org/micro/v4/register"
"go.unistack.org/micro/v4/sync"
"go.unistack.org/micro/v4/tracer" "go.unistack.org/micro/v4/tracer"
) )
@ -36,22 +37,27 @@ type Options struct {
Name string Name string
// Address holds the broker address // Address holds the broker address
Address []string Address []string
Wait *sync.WaitGroup
GracefulTimeout time.Duration
} }
// NewOptions create new Options // NewOptions create new Options
func NewOptions(opts ...options.Option) Options { func NewOptions(opts ...options.Option) Options {
options := Options{ newOpts := Options{
Register: register.DefaultRegister, Register: register.DefaultRegister,
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,
Context: context.Background(), Context: context.Background(),
Meter: meter.DefaultMeter, Meter: meter.DefaultMeter,
Codecs: make(map[string]codec.Codec), Codecs: make(map[string]codec.Codec),
Tracer: tracer.DefaultTracer, Tracer: tracer.DefaultTracer,
GracefulTimeout: DefaultGracefulTimeout,
} }
for _, o := range opts { for _, o := range opts {
o(&options) o(&newOpts)
} }
return options return newOpts
} }
// PublishOptions struct // PublishOptions struct