[rabbitmq-discuss] Confirm if the message was published

Guilherme Labigalini guilherme.labigalini at gmail.com
Wed Jul 10 18:24:48 BST 2013


Hello,

I've a C# client and I want to make sure that my published messages were
received and saved to the disk. I've create a small program that send a lot
of messages to a exchange and confirm (for each message) if it was received.

I'm using channel.ConfirmSelect and channel.WaitForConfirms, it works fine
for the first 3300 messages, but after that the the WaitForConfirms is
returning TIMEOUT.

I also tried to use channel.TxSelect / channel.TxCommit, but when there is
no free diskspace on the server, the commit operation is waiting forever.

Do you know if what I'm doing is right?  Below is the code of my
application.

Thanks

            ConnectionFactory factory = new ConnectionFactory();
            factory.HostName = ("serverName");

            var d1 = DateTime.Now;

            bool commit = true;

            using (IConnection connection = factory.CreateConnection())
            {
                using (IModel channel = connection.CreateModel())
                {
                    var properties = channel.CreateBasicProperties();
                    properties.SetPersistent(true);
                    channel.ConfirmSelect();

                    int x = 0;
                    do
                    {
                        string routeKey;

                        var dt = DateTime.Now;

                        routeKey = String.Empty;

                        var message = x.ToString() + "." + new string('a',
1024*100);

                        //channel.TxSelect();, commented , using
ConfirmSelect

                        var body =
Encoding.ASCII.GetBytes(message.ToString());
                        channel.BasicPublish(EXCHANGE_NAME, routeKey,
properties, body);

                        bool timedOut;
                        channel.WaitForConfirms(TimeSpan.FromSeconds(5),
out timedOut);

                        if (timedOut)
                        {
                            // unable to post the message
                            throw new Exception("Unable to add more
messages " + x); ;
                        }

                        //if (commit) , commented , using WaitForConfirms
                        //    channel.TxCommit();
                        //else
                        //    channel.TxRollback();

                        if (x % 100 == 0)
                            Console.WriteLine("Message '{0}' is sent", x);
                        Thread.Sleep(5);

                    } while (++x < TOTAL_TO_SEND);

                    Console.WriteLine("total time = " + (DateTime.Now -
d1));
                }
            }
        }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130710/3c2cc89a/attachment.htm>


More information about the rabbitmq-discuss mailing list