title: RabbitMQ consumer in Go
body: <p>I am trying to write a RabbitMQ Consumer in Go. Which is suppose to take the 5 objects at a time from the queue and process them. Moreover, it is suppose to acknowledge if successfully processed else send to the dead-letter queue for 5 times and then discard, it should be running infinitely and handling the cancellation event of the consumer. 
  I have few questions :</p>
  
  <ol>
  <li>Is there any concept of <code>BasicConsumer</code> vs <code>EventingBasicConsumer</code>  in RabbitMq-go <a href="http://www.jarloo.com/listening-to-rabbitmq-events/" rel="nofollow">Reference</a>?</li>
  <li>What is <code>Model</code> in RabbitMQ and is it there in RabbitMq-go?</li>
  <li>How to send the objects when failed to dead-letter queue and again re-queue them after <code>ttl</code></li>
  <li>What is the significance of <code>consumerTag</code> argument in the <code>ch.Consume</code> function in the below code</li>
  <li>Should we use the <code>channel.Get()</code> or <code>channel.Consume()</code> for this scenario?</li>
  </ol>
  
  <p>What are the changes i need to make in the below code to meet above requirement. I am asking this because i couldn't find decent documentation of RabbitMq-Go.</p>
  
  <pre><code>   func main() {
  
          consumer()        
      }
  
      func consumer() {
  
          objConsumerConn := &amp;rabbitMQConn{queueName: "EventCaptureData", conn: nil}      
          initializeConn(&amp;objConsumerConn.conn)
  
  
          ch, err := objConsumerConn.conn.Channel()
          failOnError(err, "Failed to open a channel")
          defer ch.Close()
  
          msgs, err := ch.Consume(
                  objConsumerConn.queueName, // queue
                  "demo1",     // consumerTag
                  false,   // auto-ack
                  false,  // exclusive
                  false,  // no-local
                  false,  // no-wait
                  nil,    // args
          )
          failOnError(err, "Failed to register a consumer")
  
          forever := make(chan bool)
  
          go func() {
              for d := range msgs {                  
                  k := new(EventCaptureData)
                  b := bytes.Buffer{}
                  b.Write(d.Body)
                  dec := gob.NewDecoder(&amp;b)  
                  err := dec.Decode(&amp;k)
                  d.Ack(true)  
  
                  if err != nil { fmt.Println("failed to fetch the data from consumer", err); }
                      fmt.Println(k)                        
              }
          }()      
  
          log.Printf(" Waiting for Messages to process. To exit press CTRL+C ")
          &lt;-forever
  
      }
  </code></pre>
  
  <p><strong>Edited question:</strong></p>
  
  <p>I have delayed the processing of the messages as suggested in the links <a href="http://yuserinterface.com/dev/2013/01/08/how-to-schedule-delay-messages-with-rabbitmq-using-a-dead-letter-exchange/" rel="nofollow">link1</a> <a href="http://www.kuntalganguly.com/2015/02/delay-or-schedule-message-delivery-with.html" rel="nofollow">link2</a>. But the problem is messages are getting back to their original queue from dead-lettered queue even after ttl. I am using <code>RabbitMQ 3.0.0</code>. Can anyone point out what is the problem?</p>