Open hanwenbo opened 6 hours ago
需要增加
// WithPublisherConfirms enables publisher confirms.
func WithPublisherConfirms(enable bool) ProducerOption {
return func(o *producerOptions) {
o.publisherConfirms = enable
}
}
type producerOptions struct {
exchangeDeclare *exchangeDeclareOptions
queueDeclare *queueDeclareOptions
queueBind *queueBindOptions
deadLetter *deadLetterOptions
isPersistent bool // is it persistent
mandatory bool
publisherConfirms bool // enable publisher confirms
}
func NewProducer(exchange *Exchange, queueName string, connection *Connection, opts ...ProducerOption) (*Producer, error) {
.........
if o.publisherConfirms {
if err := ch.Confirm(false); err != nil {
_ = ch.Close()
return nil, fmt.Errorf("channel could not be put into confirm mode: %w", err)
}
}
``
这个目前对我来说不是很关键,主要是发送到错误的exchange 如果存在confirm配置 是可以报错的
https://github.com/zhufuyi/sponge/blob/main/pkg/rabbitmq/README.md
没有 publisherConfirms bool // enable publisher confirms