Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8649353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:32:25+00:00 2026-06-12T13:32:25+00:00

I have the following code to declare a queue: Connection connection = RabbitConnection.getConnection(); Channel

  • 0

I have the following code to declare a queue:

Connection connection = RabbitConnection.getConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(getQueueName(), false, false, false, null);
consumer = new QueueingConsumer(channel);
channel.basicConsume(getQueueName(), true,consumer);

and the following to get the next Delivery object and process it:

    Delivery delivery = null;
    T queue = null;

    //loop over, continuously retrieving messages
    while(true) {

        try {
            delivery = consumer.nextDelivery();
            queue = deserialise(delivery.getBody());

            process(queue);

        } catch (ShutdownSignalException e) {
            logger.warn("Shutodwon signal received.");
            break;
        } catch (ConsumerCancelledException e) {
            logger.warn("Consumer cancelled exception: {}",e.getMessage());
            break;
        } catch (InterruptedException e) {
            logger.warn("Interuption exception: {}", e);
            break;
        }
    }

The deserialise code. As you can see I’m using Kryo:

public T deserialise(byte[] body) {
    Kryo kryo= new Kryo();
    Input input = new Input(body);
    T deserialised = kryo.readObject(input, getQueueClass());
    input.close();

    return deserialised;
}

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.

Do I need to do anything to tell Rabbit to release resources?

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:32:27+00:00Added an answer on June 12, 2026 at 1:32 pm

    My mistake was that I was setting my channel to auto ack. This mean that every message from Rabbit was getting ack’d (acknologed as being recieved). I have fixed (and tested) this by decalaring the channel to not auto-ack: channel.basicConsume(getQueueName(), false,consumer); and after I process queue, I then ack the message: consumer.getChannel().basicAck(delivery.getEnvelope().getDeliveryTag(), false);.

    This is what my queue decleration now looks like:

            Connection connection = RabbitConnection.getConnection();
            Channel channel = connection.createChannel();
            channel.queueDeclare(getQueueName(), false, false, false, null);
            consumer = new QueueingConsumer(channel);
            channel.basicConsume(getQueueName(), false,consumer);
    

    and the following to process the queue:

        Delivery delivery = null;
        T queue = null;
    
        //loop over, continuously retrieving messages
        while(true) {
    
            try {
                delivery = consumer.nextDelivery();
                queue = deserialise(delivery.getBody());
                process(queue);
                consumer.getChannel().basicAck(delivery.getEnvelope().getDeliveryTag(), false);
    
            } catch (ShutdownSignalException e) {
                logger.warn("Shutodwon signal received.");
                break;
            } catch (ConsumerCancelledException e) {
                logger.warn("Consumer cancelled exception: {}",e.getMessage());
                break;
            } catch (InterruptedException e) {
                logger.warn("Interuption exception: {}", e);
                break;
            } catch (IOException e) {
                logger.error("Could not ack message: {}",e);
                break;
            }
        }
    

    I can now see in the RabbitMQ Management screen that the messages are being delivered at a very high rate but that they are not being ack’d at that rate. If I then kill my consumer, within about 30s all of those non-ack’d messages are moved back to the Ready queue. One of the improvements that I will make is to set the basicQos value: channel.basicQos(10); so that there aren’t too many messages delivered but non-ack’d. This is desirable because it means that I can fire up another consumer onto the same queue and start processing the queue rather than it all ending up in memory non-ack’d and not available to other consumers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: DECLARE @testDate date --SET @testDate=dateadd(wk, 5830, 0) SET @testDate='2011-09-26
I have following tsql code in sql server 2008: declare @ID INT SET @ID
I have the following code: DECLARE @temp_table_1 TABLE (id int identity(0, 1), col_1 varchar(50)),
I have the following code: #include<stdio.h> int main() { int(* a)[10]; //declare a as
I have following code and it returns false for @B LIKE @A comparison in
I have the following code: DECLARE @monthPassed VARCHAR(MAX) SET @monthPassed = '2010' DECLARE @yearPassed
In SQL I have the following code fragment : DECLARE @DayPart as datetime, @TimePart
I have the following code where I want to declare an object inside an
I'm working with SQL 2005, and have the following code: DECLARE @exist4 INT IF
I have the following code which works fine and returns the expected results: DECLARE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.