Skip to content

Commit

Permalink
Merge pull request #8 from djumanoff/feature/unbind_option
Browse files Browse the repository at this point in the history
feat: unbind option
  • Loading branch information
slvsat authored Jul 1, 2020
2 parents 5a74442 + db19975 commit 07ec149
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ require (
github.com/sirupsen/logrus v1.1.0
github.com/streadway/amqp v0.0.0-20180806233856-70e15c650864
)

go 1.13
20 changes: 14 additions & 6 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type (
ServerConfig struct {
RequestX string
ResponseX string
UnbindQsAtStop bool
UnbindExAtStop bool
}

server struct {
Expand All @@ -36,6 +38,8 @@ type (

requestX string
responseX string
unbindQsAtStop bool
unbindExAtStop bool

qs []*Queue
xs []*Exchange
Expand Down Expand Up @@ -307,14 +311,18 @@ func (srv *server) Endpoint(endpoint string, handler Handler) error {
}

func (srv *server) cleanup() error {
srv.sess.log.Info("started cleanup server rec channels")
if err := srv.cleanupRec(); err != nil {
return err
if srv.unbindQsAtStop {
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 srv.unbindExAtStop {
srv.sess.log.Info("started cleanup server sen channels")
if err := srv.cleanupSen(); err != nil {
return err
}
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 07ec149

Please sign in to comment.