<div dir="ltr">Hello,<div><br></div><div>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.</div>
<div><br></div><div>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. </div><div><br></div><div style>
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. </div><div style><br></div><div style>Do you know if what I'm doing is right? Below is the code of my application.</div>
<div style><br></div><div style>Thanks</div><div style><br></div><div style><div> ConnectionFactory factory = new ConnectionFactory();</div><div> factory.HostName = ("serverName");</div><div>
</div><div> var d1 = DateTime.Now;</div><div><br></div><div> bool commit = true;</div><div><br></div><div> using (IConnection connection = factory.CreateConnection())</div><div>
{</div><div> using (IModel channel = connection.CreateModel())</div><div> { </div><div> var properties = channel.CreateBasicProperties();</div><div> properties.SetPersistent(true);</div>
<div> channel.ConfirmSelect();<br></div><div><br></div><div> int x = 0;</div><div> do</div><div> {</div><div> string routeKey;</div>
<div><br></div><div> var dt = DateTime.Now;</div><div><br></div><div> routeKey = String.Empty; </div><div><br></div><div> var message = x.ToString() + "." + new string('a', 1024*100);</div>
<div> </div><div> //channel.TxSelect();, commented , using ConfirmSelect</div><div><br></div><div> var body = Encoding.ASCII.GetBytes(message.ToString());</div>
<div> channel.BasicPublish(EXCHANGE_NAME, routeKey, properties, body);</div><div><br></div><div> bool timedOut;</div><div> channel.WaitForConfirms(TimeSpan.FromSeconds(5), out timedOut);</div>
<div><br></div><div> if (timedOut)</div><div> {</div><div> // unable to post the message</div><div> throw new Exception("Unable to add more messages " + x); ;</div>
<div> }</div><div><br></div><div> //if (commit) , commented , using WaitForConfirms</div><div> // channel.TxCommit();</div><div> //else</div>
<div> // channel.TxRollback();</div><div><br></div><div> if (x % 100 == 0) </div><div> Console.WriteLine("Message '{0}' is sent", x);</div>
<div> Thread.Sleep(5);</div><div><br></div><div> } while (++x < TOTAL_TO_SEND);</div><div><br></div><div> Console.WriteLine("total time = " + (DateTime.Now - d1));</div>
<div> }</div><div> }</div><div> }</div></div><div><br></div></div>