0

I am using ActiveMQ in my app. My question is how to delete messages that ı consumed successfully from kahadb. Because if it is not deleted, my db.data file is growing up constantly.

Here is my consumer;

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:8182");
    Connection connection = connectionFactory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue("TEST.FOO");
    MessageConsumer consumer = session.createConsumer(destination);

    MessageListener listner = new MessageListener() {
        int count = 0;

        public void onMessage(Message message) {
            if (message instanceof ObjectMessage) {
                ObjectMessage objectMessage = (ObjectMessage) message;
                ResponseDuration responseDuration = null;
                try {
                    responseDuration = (ResponseDuration) objectMessage.getObject();
                    System.out.println("Received Time : " + new Date() + "Received: " + responseDuration.toString());
                } catch (JMSException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

                try {
                    ResponseDurationOperations.insertResponseDurations(responseDuration);
                    count++;
                    System.out.println("Count = " + count);
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    };
    consumer.setMessageListener(listner);
turkuaz07
  • 101
  • 1
  • 10
  • any help, I just wanna delete messages from db.data file after consumer got the message – turkuaz07 Mar 02 '14 at 20:40
  • My question is reverse, I am using Oracle for persistence. After message is consumed it gets deleted from database, how can I keep messages forever? – Nikhil Joshi Jul 01 '14 at 12:48
  • @NikhilJoshi: I am also searching for your question. Currently for us the consumer is sending every consumed message in a new protocol queue. So we have queues for every day with consumed messages. But for sure there has to be something inight ActiveMQ itself? – timguy Feb 26 '16 at 09:18

1 Answers1

2

Seems that ActiveMQ has a different meaning for what it means with persistance than you (and me as well). Persistence is defined not to persist for ever but just to make you safe from message loss when you restart the server. See this

One option for you could be to switch off the persistence. See here. For example by this way:

ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
timguy
  • 2,063
  • 2
  • 21
  • 40