Example #1
0
 private void Consumer_Received1(object sender, BasicDeliverEventArgs e)
 {
     try
     {
         var body    = e.Body;
         var content = Encoding.UTF8.GetString(body);
         using (StreamWriter sw = new StreamWriter(@"C:\wahid off\test.txt", true))
         {
             sw.WriteLine("DLX " + content);
         }
         Instance.ConsumerAcknowledgements().BasicReject(e.DeliveryTag, false);
         using (StreamWriter sw = new StreamWriter(@"C:\wahid off\test1.txt", true))
         {
             sw.WriteLine("DLX redeL : " + e.Redelivered);
             sw.WriteLine(e.DeliveryTag);
             sw.WriteLine(Convert.ToInt32(e.BasicProperties.Headers["X-delivered-Count"]));
         }
     }
     catch (Exception ex)
     {
         using (StreamWriter sw = new StreamWriter(@"C:\wahid off\testExce.txt", true))
         {
             sw.WriteLine(ex.ToString());
         }
     }
 }
Example #2
0
        private void Consumer_Received(object sender, BasicDeliverEventArgs e)
        {
            try
            {
                var body    = e.Body;
                var content = Encoding.UTF8.GetString(body);
                using (StreamWriter sw = new StreamWriter(@"C:\wahid off\test.txt", true))
                {
                    sw.WriteLine(content + " " + DateTime.Now);
                }
                //Instance.ConsumerAcknowledgements().BasicAck(e.DeliveryTag, false);
                if (e.BasicProperties.Headers != null)
                {
                    var header           = e.BasicProperties.Headers;
                    int redeliveredCount = Convert.ToInt32(header["X-delivered-Count"]);
                    if (redeliveredCount <= 1)
                    {
                        e.BasicProperties.Headers["X-delivered-Count"] = redeliveredCount++;
                        rmq.ConsumerAcknowledgements().BasicAck(e.DeliveryTag, false);
                        Redeliver(e.Body, redeliveredCount);
                    }
                    else
                    {
                        rmq.ConsumerAcknowledgements().BasicReject(e.DeliveryTag, false);
                    }
                }
                else
                {
                    rmq.ConsumerAcknowledgements().BasicReject(e.DeliveryTag, false);
                }

                using (StreamWriter sw = new StreamWriter(@"C:\wahid off\test1.txt", true))
                {
                    sw.WriteLine("redeL : " + e.Redelivered);
                    sw.WriteLine(e.DeliveryTag);
                    sw.WriteLine(Convert.ToInt32(e.BasicProperties.Headers["X-delivered-Count"]));
                }
            }
            catch (Exception ex)
            {
                using (StreamWriter sw = new StreamWriter(@"C:\wahid off\testExce.txt", true))
                {
                    sw.WriteLine(ex.ToString());
                }
            }
        }