From 0220540c51d6d1859873e19ae1e234eeaa6b7eb0 Mon Sep 17 00:00:00 2001 From: Sattar Salambayev Date: Wed, 1 Jul 2020 13:20:32 +0600 Subject: [PATCH 1/2] feat: unbind option --- go.mod | 2 ++ server.go | 24 ++++++++++++++++-------- session.go | 2 ++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 1fe020a..f11a844 100644 --- a/go.mod +++ b/go.mod @@ -4,3 +4,5 @@ require ( github.com/sirupsen/logrus v1.1.0 github.com/streadway/amqp v0.0.0-20180806233856-70e15c650864 ) + +go 1.13 diff --git a/server.go b/server.go index d7789e0..68c7294 100644 --- a/server.go +++ b/server.go @@ -25,6 +25,8 @@ type ( ServerConfig struct { RequestX string ResponseX string + UnbindQsAtStop bool + UnbindExAtStop bool } server struct { @@ -36,6 +38,8 @@ type ( requestX string responseX string + unbindQsAtStop bool + unbindExAtStop bool qs []*Queue xs []*Exchange @@ -85,7 +89,7 @@ func (srv *server) Start() error { //} <-srv.close - srv.cleanup() + srv.cleanup(srv.unbindQsAtStop, srv.unbindExAtStop) return nil } @@ -306,15 +310,19 @@ func (srv *server) Endpoint(endpoint string, handler Handler) error { return nil } -func (srv *server) cleanup() error { - srv.sess.log.Info("started cleanup server rec channels") - if err := srv.cleanupRec(); err != nil { - return err +func (srv *server) cleanup(unbindQs, unbindEx bool) error { + if unbindQs { + srv.sess.log.Info("started cleanup server rec channels") + if err := srv.cleanupRec(); err != nil { + return err + } } - srv.sess.log.Info("started cleanup server sen channels") - if err := srv.cleanupSen(); err != nil { - return err + if unbindEx { + srv.sess.log.Info("started cleanup server sen channels") + if err := srv.cleanupSen(); err != nil { + return err + } } return nil diff --git a/session.go b/session.go index f1975e7..62a72b1 100644 --- a/session.go +++ b/session.go @@ -154,6 +154,8 @@ func (sess *session) createServer(cfg ServerConfig) (*server, error) { close: make(chan bool), sen: sen, rec: rec, + unbindExAtStop: cfg.UnbindExAtStop, + unbindQsAtStop: cfg.UnbindQsAtStop, } senCh := sen.NotifyClose(make(chan *amqp.Error)) From db19975834a20ae94e53bebfa251a1ef47b8cbbd Mon Sep 17 00:00:00 2001 From: Sattar Salambayev Date: Wed, 1 Jul 2020 13:43:40 +0600 Subject: [PATCH 2/2] fix: args for cleanup --- server.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server.go b/server.go index 68c7294..96f7dad 100644 --- a/server.go +++ b/server.go @@ -89,7 +89,7 @@ func (srv *server) Start() error { //} <-srv.close - srv.cleanup(srv.unbindQsAtStop, srv.unbindExAtStop) + srv.cleanup() return nil } @@ -310,15 +310,15 @@ func (srv *server) Endpoint(endpoint string, handler Handler) error { return nil } -func (srv *server) cleanup(unbindQs, unbindEx bool) error { - if unbindQs { +func (srv *server) cleanup() error { + if srv.unbindQsAtStop { srv.sess.log.Info("started cleanup server rec channels") if err := srv.cleanupRec(); err != nil { return err } } - if unbindEx { + if srv.unbindExAtStop { srv.sess.log.Info("started cleanup server sen channels") if err := srv.cleanupSen(); err != nil { return err