0
  1. I am working on rabbitmq and I am confused with some points Like. I have just implemented a sample from internet which creates a queue and then it fetch the message from that queue thereby showing it on the webpage. Now my problem is:: Suppose My server has RabbitmQ installed and multiple users are accessing this website where I have implemented the rabbitmq.Now, first user sends a message but to whome it will send this message? To all the users who will open the page because the code will be common for sent message and the name of the queue will also be same.

  2. Suppose, first user send one message="Hello" on the queue "Queue1" now, one other user sends another message="Hello World" on the same queue and one more user sends a message="Hello Worl World" on the same queue. Now nth user clicks on receive message then which message will be shown to him? first ,second or third one?

  3. It means we will always have a single queue for my application?

Can somebody please guide me. I am pretty much confused...

Below I am pasting the code sample I will be using for my website

//For sending the messge
  protected void btnSendMail_Click(object sender, EventArgs e)
    {
        try
        {
            var factory = new ConnectionFactory();
            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    //  ConnectionFactory factory = new ConnectionFactory() { HostName = "localhost" };
                    // // factory.UserName = txtUserEmail.Text.ToString();
                    ////  factory.Password = "password";
                    //  factory.VirtualHost = "/";
                    //  factory.Protocol = Protocols.FromEnvironment();
                    //  factory.HostName = "localhost";
                    //  factory.Port = AmqpTcpEndpoint.UseDefaultPort;
                    //  IConnection conn = factory.CreateConnection();
                    //  using (var channel = conn.CreateModel())
                    //  {
                    //      channel.QueueDeclare("hello", false, false, false, null);
                    //      string message = "Hello World!";
                    //      var body = Encoding.UTF8.GetBytes(txtUserEmail.Text.ToString());
                    //      channel.BasicPublish("", "hello", null, body);
                    //      conn.Close();
                    //  }
                    //Sending Message
                    channel.QueueDeclare("hello1", false, false, false, null);

                    string message = txtUserEmail.Text.ToString();
                    var body = Encoding.UTF8.GetBytes(message);

                    channel.BasicPublish("", "hello1", null, body);
                    //Console.WriteLine(" [x] Sent {0}", message);
                    //Console.ReadLine();
                    Label1.Text = Encoding.Default.GetString(body);
                }
            }

        }
        catch
        {
        }
    }


//For receiving the message.
 protected void btnReceive_Click(object sender, EventArgs e)
    {
        try
        {
            //var factory = new ConnectionFactory() { HostName = "localhost" };
            //using (var connection = factory.CreateConnection())
            //{
            //    using (var channel = connection.CreateModel())
            //    {

            //        channel.QueueDeclare("hello", false, false, false, null);
            //        BasicGetResult result = channel.BasicGet("hello", false);
            //        var consumer = new QueueingBasicConsumer(channel);
            //        channel.BasicConsume("hello", true, consumer);
            //        Console.WriteLine(" [*] Waiting for messages." +
            //                                 "To exit press CTRL+C");
            //        while (true)
            //        {

            //            var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();

            //            var body = ea.Body;
            //            var message = Encoding.UTF8.GetString(body);
            //            Console.WriteLine(" [x] Received {0}", message);
            //            Label1.Text = message.ToString();
            //        }
            //    }
            //}
            var factory = new ConnectionFactory();
            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    bool noAck = false;
                    BasicGetResult result = channel.BasicGet("hello1", noAck);
                    if (result == null)
                    {

                    }
                    else
                    {
                        IBasicProperties props = result.BasicProperties;
                        byte[] Body = result.Body;
                        Label1.Text = Encoding.Default.GetString(Body);

                    }
                }
            }


        }
        catch
        {
        }
    }
10
  • I'm not very clear on the question. Which example RabbitMQ problem are you working through? RabbitMQ provides the messaging, you provide the application. Commented Sep 23, 2013 at 11:29
  • Sir, my problem is just simple. I have a website in which I am implementing rabbitMq. As you know , the site is used for sending and receiving messages. For that it creates a queue and store a message in it and uses the same queue while receiving messages.Now, suppose First user of this website sends a message and a queue saves this message, now another user sends a message , what will happen now. Should I have to create a different queue or the same one can store this. I used same queue but while receiving I am just getting the first message and not the one sent by second user. Commented Sep 23, 2013 at 11:44
  • 1
    It really depends on how you have set up RabbitMQ. Yes, you can use a single queue and process more than one message. But you have left out a lot of information. Are you using direct, fanout or topic exchange? How is your queue configured? If you show your actual code (in the question) maybe we can help :) Commented Sep 23, 2013 at 11:47
  • 1
    By setting noAck to false, you haven't acknowledge receiving the message. Try to set noAck to true. Commented Sep 23, 2013 at 12:02
  • 1
    @Sandy for us to give you a better answer to your problem we need to understand from an architectural point of view what your system is trying to accomplish. Then we can advise how best to lay it out. Saying "it needs to work for multiple users" isn't helpful. I suggest you re-write your question and tell us about the system you're building. Commented Sep 23, 2013 at 12:46

1 Answer 1

1

If you are creating a messaging system using RabbitMQ you should probably publish your messages to an exchange and then attach a queue to the exchange for each user of the site. Then have the exchange route the messages to the right user/users queue.

You need a better understanding of messaging patterns associated with the use of RabbitMQ

These tutorials would be most relevant

Publish/Subscribe http://www.rabbitmq.com/tutorials/tutorial-three-python.html

Routing http://www.rabbitmq.com/tutorials/tutorial-four-python.html

The tutorials are also available in c# if you need it.

Sign up to request clarification or add additional context in comments.

1 Comment

Sir, please give your answer more descriptively. As this would not be sufficient for me as a beginner

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.