I have the following code to declare a queue:<br><br>Connection connection = RabbitConnection.getConnection();<br>Channel channel = connection.createChannel();<br>channel.queueDeclare(getQueueName(), false, false, false, null);<br>consumer = new QueueingConsumer(channel);<br>channel.basicConsume(getQueueName(), true,consumer);<br><br>and the following to get the next Delivery object and process it:<br><br> Delivery delivery = null;<br> T queue = null;<br> <br> //loop over, continuously retrieving messages<br> while(true) {<br> <br> try {<br> delivery = consumer.nextDelivery();<br> queue = deserialise(delivery.getBody());<br> <br> process(queue);<br> <br> } catch (ShutdownSignalException e) {<br> logger.warn("Shutodwon signal received.");<br> break;<br> } catch (ConsumerCancelledException e) {<br> logger.warn("Consumer cancelled exception: {}",e.getMessage());<br> break;<br> } catch (InterruptedException e) {<br> logger.warn("Interuption exception: {}", e);<br> break;<br> }<br> }<br><br>If I run this with a queue containing a large number of objects, after approximatelly 2.7 million objects I get an out of memory exception. I found this originally by running it over night with data going in from JMeter at a rate ~90/s which at first it is consuming without any trouble, but in the morning I noticed a large number in RabbitMQ and an out of memory exception on the consumer. I ran it up again and used the Eclipse Memory Analyzer to determine where this memory was being used. From this I can see that the java.util.concurrent.LinkedBlockingQueue that is referenced by com.rabbitmq.client.QueueingConsumer is growing and growing until it runs out of memory.<br><br><p>Do I need to do anything to tell Rabbit to release resources?</p>
<p>I could increase the heap size but I'm concerned that this is just a
short term fix and there might be something in my code that could bite
me with a memory leak a few months into production deployment.</p>I have also posted this to StackOverflow: http://stackoverflow.com/questions/12687368/rabbitmq-queueingconsumer-possible-memory-leak<br>