<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-text-flowed" style="font-family: -moz-fixed;
      font-size: 14px;" lang="x-western">Hello Team,
      <br>
                                I am working out with rabbit-mq from
      some days. It is a very nice application and I am trying to
      incorporating this app into my Asp.net MVC 4.0 Web app for
      providing a facility
      <br>
                                of mailing system.  I have gone through
      the tutorials and certain examples for C#.
      <br>
      <br>
      Requirement: Sir, my requirement is to provide a mail like system
      in the web app using Rabbit-Mq. For Example: If I have one user
      logged in to my application and sends a message to another
      <br>
                              online user , I need to send the message
      to that user. I am using a very basic code given on Rabbit-mq web
      site but I am not getting an idea on how rabbit-mq will server
      this.As for   now I when I click on send message , a message is
      stored in the queue and then when I click on recieve message
      button on same page, the particular message is shown. That is just
      a template that I have designed.
      <br>
      <br>
      Can you please help me for my practical situation and I will be
      really thankful to you.
      <br>
      <br>
      I am using below Code for my template. Please send me the code to
      implement this or just guide me a path by which I can achieve
      this.
      <br>
      <br>
      <br>
      This is a view page::
      <br>
        public ActionResult Index()
      <br>
              {
      <br>
                  MessageService ObjMessageService = new
      MessageService();
      <br>
                  var model = new MessagingModel();
      <br>
                  model.MessageList =
      ObjMessageService.GetMessageDetails();
      <br>
                  return View(model);
      <br>
              }
      <br>
      <br>
      <br>
      <br>
      Below function works when "SendMessage" button is pressed
      <br>
              public ActionResult SendMessage(MessagingModel ObjModel)
      <br>
              {
      <br>
                  string Message = string.Empty;
      <br>
                  try
      <br>
                  {
      <br>
      <br>
                      //var factory = new ConnectionFactory() { HostName
      = "localhost" };
      <br>
                      //using (var connection =
      factory.CreateConnection())
      <br>
                      //using (var channel = connection.CreateModel())
      <br>
                      //{
      <br>
                      //    channel.ExchangeDeclare("logs", "fanout");
      <br>
                      //    var message = ObjModel.Message;
      <br>
                      //    var body = Encoding.UTF8.GetBytes(message);
      <br>
                      //    channel.BasicPublish("logs", "", null,
      body);
      <br>
      <br>
                      //}
      <br>
      <br>
                      var factory = new ConnectionFactory() { HostName =
      "localhost" };
      <br>
                      using (var connection =
      factory.CreateConnection())
      <br>
                      {
      <br>
                          using (var channel = connection.CreateModel())
      <br>
                          {
      <br>
                              Message = ObjModel.Message;
      <br>
                              channel.QueueDeclare("MessageQueue", true,
      false, false, null);
      <br>
                              var body =
      Encoding.UTF8.GetBytes(ObjModel.Message);
      <br>
                              //Save Message To dateBase
      <br>
      <br>
                              MessageService ObjMessageService = new
      MessageService();
      <br>
                              int displayOrder =
      ObjMessageService.GetDisplayOrder();
      <br>
                              if (displayOrder > 0)
      <br>
                              {
      <br>
                                  int NewOrder = displayOrder + 1;
      <br>
                                  tblMessageDetail ObjTBL = new
      tblMessageDetail();
      <br>
                                  ObjTBL.Message = ObjModel.Message;
      <br>
                                  ObjTBL.Sent_Date = DateTime.Now;
      <br>
                                  ObjTBL.IsReceived = false;
      <br>
                                  ObjTBL.DisplayOrder = NewOrder;
      <br>
                                  int Result =
      ObjMessageService.SaveSentMessage(ObjTBL);
      <br>
                                  if (Result == 1)
      <br>
                                  {
      <br>
                                      channel.BasicPublish("",
      "MessageQueue", null, body);
      <br>
                                  }
      <br>
                              }
      <br>
      <br>
                          }
      <br>
                      }
      <br>
                  }
      <br>
                  catch
      <br>
                  {
      <br>
                      Message = "An Error has been occurred while
      sending messages.";
      <br>
                  }
      <br>
                  return Json(new { MSG = Message });
      <br>
              }
      <br>
      <br>
      <br>
      and   Below message works for receive message::
      <br>
           [HttpPost]
      <br>
              public JsonResult RecieveMessage()
      <br>
              {
      <br>
                  string Message = string.Empty;
      <br>
                  try
      <br>
                  {
      <br>
                      //var factory = new ConnectionFactory() { HostName
      = "localhost" };
      <br>
                      //using (var connection =
      factory.CreateConnection())
      <br>
                      //{
      <br>
                      //    using (var channel =
      connection.CreateModel())
      <br>
                      //    {
      <br>
                      //        channel.ExchangeDeclare("logs",
      "fanout");
      <br>
                      //        var queueName = channel.QueueDeclare();
      <br>
                      //        channel.QueueBind(queueName, "logs",
      "");
      <br>
                      //        var consumer = new
      QueueingBasicConsumer(channel);
      <br>
                      //        var ResultBody =
      channel.BasicConsume(queueName, true, consumer);
      <br>
                      //        Message =
      Encoding.UTF8.GetString(ResultBody.ToArray()));
      <br>
                      //    }
      <br>
                      //}
      <br>
      <br>
                      var factory = new ConnectionFactory();
      <br>
                      using (var connection =
      factory.CreateConnection())
      <br>
                      {
      <br>
                          using (var channel = connection.CreateModel())
      <br>
                          {
      <br>
                              channel.QueueDeclare("MessageQueue", true,
      false, false, null);
      <br>
                              bool noAck = true;
      <br>
                              BasicGetResult result =
      channel.BasicGet("MessageQueue", noAck);
      <br>
                              if (result == null)
      <br>
                              {
      <br>
                                  Message = "No Messages Found.";
      <br>
                              }
      <br>
                              else
      <br>
                              {
      <br>
                                  IBasicProperties props =
      result.BasicProperties;
      <br>
                                  byte[] Body = result.Body;
      <br>
                                  Message =
      Encoding.Default.GetString(Body);
      <br>
                              }
      <br>
                          }
      <br>
                      }
      <br>
                  }
      <br>
                  catch
      <br>
                  {
      <br>
                      Message = "An Error has been occurred while
      receiving messages.";
      <br>
                  }
      <br>
                  return Json(new { MSG = Message });
      <br>
              }
      <br>
      <br>
      I have attached a  image of the page which can may be give you an
      Idea of the template that I have designed::
      <br>
      Actually the table just shows the sent messages which I save in
      databse when I click on send message button.
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
    </div>
    <br>
    <fieldset class="mimeAttachmentHeader"><legend
        class="mimeAttachmentHeaderName">CaptureMessaging.PNG</legend></fieldset>
    <br>
    <center><img class="moz-attached-image" shrinktofit="yes"
        src="cid:part1.04080406.01050804@kindlebit.com"></center>
    <p>
    </p>
  
<br /><br />
<hr style='border:none; color:#909090; background-color:#B0B0B0; height: 1px; width: 99%;' />
<table style='border-collapse:collapse;border:none;'>
        <tr>
                <td style='border:none;padding:0px 15px 0px 8px'>
                        <a href="http://www.avast.com/">
                                <img border=0 src="http://static.avast.com/emails/avast-mail-stamp.png" />
                        </a>
                </td>
                <td>
                        <p style='color:#3d4d5a; font-family:"Calibri","Verdana","Arial","Helvetica"; font-size:12pt;'>
                                This email is free from viruses and malware because <a href="http://www.avast.com/">avast! Antivirus</a> protection is active.
                        </p>
                </td>
        </tr>
</table>
<br />
</body>
</html>