From c3cabc1fe5205c2fc8c40b20220d5f5ae9c0bb9f Mon Sep 17 00:00:00 2001 From: Evstigneev Denis Date: Sun, 7 Apr 2024 20:48:47 +0300 Subject: [PATCH 1/2] add options in broker --- .gitignore | 3 +++ broker/broker.go | 3 +++ broker/options.go | 24 +++++++++++++++--------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 500d68ca..c2fff381 100644 --- a/.gitignore +++ b/.gitignore @@ -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] diff --git a/broker/broker.go b/broker/broker.go index 53099b7a..7e8dd9ae 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -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. diff --git a/broker/options.go b/broker/options.go index ddc12e32..b1c2fea4 100644 --- a/broker/options.go +++ b/broker/options.go @@ -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{ - Register: register.DefaultRegister, - Logger: logger.DefaultLogger, - Context: context.Background(), - Meter: meter.DefaultMeter, - Codecs: make(map[string]codec.Codec), - Tracer: tracer.DefaultTracer, + 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 From 56d33ae823991af8f7d23da7c2dcdb2eb2d37a99 Mon Sep 17 00:00:00 2001 From: devstigneev Date: Sun, 7 Apr 2024 21:17:42 +0300 Subject: [PATCH 2/2] rename path to sync --- broker/options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/broker/options.go b/broker/options.go index b1c2fea4..aa3a7272 100644 --- a/broker/options.go +++ b/broker/options.go @@ -3,7 +3,6 @@ package broker import ( "context" "crypto/tls" - "sync" "time" "go.unistack.org/micro/v4/codec" @@ -12,6 +11,7 @@ import ( "go.unistack.org/micro/v4/meter" "go.unistack.org/micro/v4/options" "go.unistack.org/micro/v4/register" + "go.unistack.org/micro/v4/sync" "go.unistack.org/micro/v4/tracer" )