Closed parsibox closed 1 year ago
you need to define a handler function when NewConsumer, the func type is type Handler func(d Delivery) (action Action)
.
return param: Action
, you can choonse Manual
to ACK manualy
consumer, err := rabbitmq.NewConsumer(
conn,
func(d rabbitmq.Delivery) rabbitmq.Action {
log.Printf("consumed: %v", string(d.Body))
// if You choose return rabbitmq.Manual at the end of the method,you must call d.Ack() or d.Nack() to ack or nack this msg
d.Ack(true)
// rabbitmq.Ack, rabbitmq.NackDiscard, rabbitmq.NackRequeue
return rabbitmq.Manual
},
"my_queue",
rabbitmq.WithConsumerOptionsRoutingKey("my_routing_key"),
rabbitmq.WithConsumerOptionsExchangeName("events"),
rabbitmq.WithConsumerOptionsExchangeDeclare,
)
i now this but i mean send d.Ack(true) in another method not in handler function ,
Surely, you need to pass the delivery instance in the other function as well
when i do that i get this error :
failed to acknowledge message: Exception (504) Reason: "channel/connection is not open
i call other function with go ( goroutine ) and get error after some work
No making it simple to Ack outside of the handler is out of scope of this library. Just use AMQP for that
hi can we do Ack manualy? for example we pass d variable with go to another method and then on that method directly do ACK?