zhufuyi / sponge

Sponge is a powerful Go development framework, it's easy to develop web, gRPC and microservice projects.
https://go-sponge.com
MIT License
1.47k stars 146 forks source link

rabbit mq 没有确认参数 #89

Open hanwenbo opened 6 hours ago

hanwenbo commented 6 hours ago

https://github.com/zhufuyi/sponge/blob/main/pkg/rabbitmq/README.md

func defaultProducerOptions() *producerOptions {
    return &producerOptions{
        exchangeDeclare: defaultExchangeDeclareOptions(),
        queueDeclare:    defaultQueueDeclareOptions(),
        queueBind:       defaultQueueBindOptions(),
        deadLetter:      defaultDeadLetterOptions(),

        isPersistent: true,
        mandatory:    true,
    }
}

没有 publisherConfirms bool // enable publisher confirms

hanwenbo commented 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)
        }
    }

``
hanwenbo commented 5 hours ago

这个目前对我来说不是很关键,主要是发送到错误的exchange 如果存在confirm配置 是可以报错的