Browse Source

Copy default options to not change it

pull/152/head
Henrik Hofmeister 2 years ago
parent
commit
22facb590d
3 changed files with 13 additions and 8 deletions
  1. +5
    -5
      consume.go
  2. +3
    -3
      publish.go
  3. +5
    -0
      publisher_options.go

+ 5
- 5
consume.go View File

@ -54,9 +54,9 @@ func NewConsumer(
optionFuncs ...func(*ConsumerOptions),
) (*Consumer, error) {
defaultOptions := getDefaultConsumerOptions(queue)
options := &defaultOptions
options := defaultOptions
for _, optionFunc := range optionFuncs {
optionFunc(options)
optionFunc(&options)
}
if conn.connectionManager == nil {
@ -73,14 +73,14 @@ func NewConsumer(
chanManager: chanManager,
reconnectErrCh: reconnectErrCh,
closeConnectionToManagerCh: closeCh,
options: *options,
options: options,
isClosedMux: &sync.RWMutex{},
isClosed: false,
}
err = consumer.startGoroutines(
handler,
*options,
options,
)
if err != nil {
return nil, err
@ -91,7 +91,7 @@ func NewConsumer(
consumer.options.Logger.Infof("successful consumer recovery from: %v", err)
err = consumer.startGoroutines(
handler,
*options,
options,
)
if err != nil {
consumer.options.Logger.Fatalf("error restarting consumer goroutines after cancel or close: %v", err)


+ 3
- 3
publish.go View File

@ -69,9 +69,9 @@ type PublisherConfirmation []*amqp.DeferredConfirmation
// will fail with an error when the server is requesting a slowdown
func NewPublisher(conn *Conn, optionFuncs ...func(*PublisherOptions)) (*Publisher, error) {
defaultOptions := getDefaultPublisherOptions()
options := &defaultOptions
options := defaultOptions
for _, optionFunc := range optionFuncs {
optionFunc(options)
optionFunc(&options)
}
if conn.connectionManager == nil {
@ -96,7 +96,7 @@ func NewPublisher(conn *Conn, optionFuncs ...func(*PublisherOptions)) (*Publishe
handlerMux: &sync.Mutex{},
notifyReturnHandler: nil,
notifyPublishHandler: nil,
options: *options,
options: options,
}
err = publisher.startup()


+ 5
- 0
publisher_options.go View File

@ -59,6 +59,11 @@ func WithPublisherOptionsExchangeName(name string) func(*PublisherOptions) {
options.ExchangeName = name
}
}
func WithPublisherOptionsConfirmMode(confirm bool) func(*PublisherOptions) {
return func(options *PublisherOptions) {
options.ConfirmMode = confirm
}
}
// WithPublisherOptionsExchangeKind ensures the queue is a durable queue
func WithPublisherOptionsExchangeKind(kind string) func(*PublisherOptions) {


Loading…
Cancel
Save