Skip to content

What should I do if publishing confirm failed with the 'deliveryTag' #507

Description

@Icarus9913

Sorry for asking this simple question. If I publish one msg and get the confirmations (confirmations.ack==false). In this situation, how can I re-publish this msg? Should I use channel.Nack()? And how can I imitate the return confirmation ack is false?

  func main() {
	conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
	if nil != err {
		panic(err)
	}

	ch, err := conn.Channel()
	if nil != err {
		panic(err)
	}

	queue, err := ch.QueueDeclare("hey", true, false, false, false, nil)
	if nil != err {
		panic(err)
	}

	if err = ch.Confirm(false); nil != err {
		panic(err)
	}

	confirms := ch.NotifyPublish(make(chan amqp.Confirmation, 1))

	body := "hello"
	err = ch.Publish("", queue.Name, false, false,
		amqp.Publishing{
			ContentType: "text/plain",
			Body:        []byte(body),
		},
	)
	if nil != err {
		panic("sending failed: " + err.Error())
	}

	if confirmed := <-confirms; confirmed.Ack {
		fmt.Println("good")
	} else {
		fmt.Println("what should I do?")
		tag := confirmed.DeliveryTag
		ch.Nack(tag, false, true) //Is that right to use this method? But I can't imitate this situation. I want it to re-publish
	}
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions