[rabbitmq-discuss] TTL

Derek Greer dbgreer at gmail.com
Thu Apr 4 21:35:16 BST 2013


A note of clarification, I was using values of 1, 3, 5, 10 milliseconds,
not seconds, to give the server enough time to expire a 1 millisecond TTL
on a message.  I discovered 10 milliseconds still wasn't always successful.
 Regardless, I would expect to only have to sleep for 1 millisecond to give
the sever enough time to remove a 1 millisecond TTL message.  Here's my
example using the .Net API in which I'm seeing about a 3% failure rate:


using System;
using System.Text;
using System.Threading;
using RabbitMQ.Client;
using RabbitMQ.Client.Framing.v0_9_1;

namespace RabbitTTLTest
{
class Program
{
static void Main(string[] args)
{
var messages = 0;
var iterations = 1000;

for (int i = 0; i < iterations; i++)
messages += SendAndReceive();

Console.WriteLine("Received {0} messages", messages);
Console.WriteLine("API works {0}% of the time.", ((iterations - messages) /
(decimal)iterations) * 100);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}

static int SendAndReceive()
{
ProduceMessage();
Thread.Sleep(10);
return ConsumeMessage();
}

static int ConsumeMessage()
{
int messages = 0;
var connectionFactory = new ConnectionFactory();
IConnection connection = connectionFactory.CreateConnection();
IModel channel = connection.CreateModel();
channel.QueueDeclare("sample-queue", false, false, false, null);
BasicGetResult result = channel.BasicGet("sample-queue", true);
if (result != null)
{
messages++;
string message = Encoding.UTF8.GetString(result.Body);
Console.WriteLine(message);
}
channel.Close();
connection.Close();
return messages;
}

static void ProduceMessage()
{
var connectionFactory = new ConnectionFactory();
IConnection connection = connectionFactory.CreateConnection();
IModel channel = connection.CreateModel();
channel.QueueDeclare("sample-queue", false, false, false, null);
byte[] message = Encoding.UTF8.GetBytes("Hello, World!");
var properties = new BasicProperties();
properties.Expiration = "1";
channel.BasicPublish(string.Empty, "sample-queue", properties, message);
channel.Close();
connection.Close();
}
}
}


On Thu, Apr 4, 2013 at 3:10 PM, Derek Greer <dbgreer at gmail.com> wrote:

> Perhaps an important note, I'm using the pull API which I'm remembering
> doesn't create a "consumer".
>
> I'll pull together a small example and post it here.
>
>
> On Thu, Apr 4, 2013 at 2:48 PM, Michael Klishin <
> michael.s.klishin at gmail.com> wrote:
>
>> 2013/4/4 Derek Greer <dbgreer at gmail.com>
>>
>>> No, I'm seeing my consumer retrieve a message which should have been
>>> expired.
>>
>>
>> Derek,
>>
>> Can you post a code example that reproduces the problem?
>>
>> Thanks.
>> --
>> MK
>>
>> http://github.com/michaelklishin
>> http://twitter.com/michaelklishin
>>
>> _______________________________________________
>> rabbitmq-discuss mailing list
>> rabbitmq-discuss at lists.rabbitmq.com
>> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>>
>>
>
>
> --
> ___________________________________________
> Derek Greer
> dbgreer at gmail.com     | @derekgreer <http://twitter.com/derekgreer>
> lostechies.com <http://derekgreer.lostechies.com/> | freshbrewedcode.com<http://derekgreer.freshbrewedcode.com>
>  | aspiringcraftsman.com
> ___________________________________________
>
>


-- 
___________________________________________
Derek Greer
dbgreer at gmail.com     | @derekgreer <http://twitter.com/derekgreer>
lostechies.com <http://derekgreer.lostechies.com/> |
freshbrewedcode.com<http://derekgreer.freshbrewedcode.com>
 | aspiringcraftsman.com
___________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130404/b64355c5/attachment.htm>


More information about the rabbitmq-discuss mailing list