activemq删除消费的消息

时间:2014-02-26 09:40:39

标签: activemq producer-consumer

我在我的应用中使用ActiveMQ。我的问题是如何删除从kahadb成功消费的消息。因为如果没有删除它,我的db.data文件就会不断成长。

这是我的消费者;

    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);

1 个答案:

答案 0 :(得分:1)

似乎ActiveMQ对于持久性的含义与你(以及我)的含义有不同的含义。 持久性定义为不会永久存在,只是为了让您在重新启动服务器时不会丢失消息。 See this

您可以选择关闭持久性。见here。 例如通过这种方式:

ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");