From c2808679c33c320f9b241bcb0e88a7565e50ef74 Mon Sep 17 00:00:00 2001 From: devstigneev Date: Sun, 7 Apr 2024 20:53:01 +0300 Subject: [PATCH 1/2] add options in broker --- .gitignore | 3 +++ broker/broker.go | 3 +++ broker/options.go | 18 ++++++++++++------ 3 files changed, 18 insertions(+), 6 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 11e029ed..80585c4c 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -4,6 +4,7 @@ package broker // import "go.unistack.org/micro/v3/broker" import ( "context" "errors" + "time" "go.unistack.org/micro/v3/codec" "go.unistack.org/micro/v3/metadata" @@ -17,6 +18,8 @@ var ( ErrNotConnected = errors.New("broker not connected") // ErrDisconnected returns when broker disconnected ErrDisconnected = errors.New("broker disconnected") + // DefaultGracefulTimeout + DefaultGracefulTimeout = 5 * time.Second ) // Broker is an interface used for asynchronous messaging. diff --git a/broker/options.go b/broker/options.go index 0e4a8c75..a27c445a 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/v3/codec" @@ -36,17 +37,22 @@ type Options struct { Name string // Addrs holds the broker address Addrs []string + + Wait *sync.WaitGroup + + GracefulTimeout time.Duration } // NewOptions create new Options func NewOptions(opts ...Option) Options { options := Options{ - Register: register.DefaultRegister, - Logger: logger.DefaultLogger, - Context: context.Background(), - Meter: meter.DefaultMeter, - Codec: codec.DefaultCodec, - Tracer: tracer.DefaultTracer, + Register: register.DefaultRegister, + Logger: logger.DefaultLogger, + Context: context.Background(), + Meter: meter.DefaultMeter, + Codec: codec.DefaultCodec, + Tracer: tracer.DefaultTracer, + GracefulTimeout: DefaultGracefulTimeout, } for _, o := range opts { o(&options) -- 2.45.2 From 8254456c8becf8d7e57ad5b8b5bcd368ed54f812 Mon Sep 17 00:00:00 2001 From: devstigneev Date: Sun, 7 Apr 2024 21:16:50 +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 a27c445a..c5e91263 100644 --- a/broker/options.go +++ b/broker/options.go @@ -3,13 +3,13 @@ package broker import ( "context" "crypto/tls" - "sync" "time" "go.unistack.org/micro/v3/codec" "go.unistack.org/micro/v3/logger" "go.unistack.org/micro/v3/meter" "go.unistack.org/micro/v3/register" + "go.unistack.org/micro/v3/sync" "go.unistack.org/micro/v3/tracer" ) -- 2.45.2