Active MQ:Pending,Enqueued和Dequeued计数不符合

时间:2014-02-14 15:44:31

标签: java jms activemq

我有queue_pending1queue_pending2,每个100 messages。我有一个专门的进程监听每个队列,它从相应的队列中获取待处理的消息,处理queue_processed上的记录和位置。

queue_pending1 ---> dequeue -----> process#1 -----> enqueue -----> queue_processed.
queue_pending2 ---> dequeue -----> process#2 -----> enqueue -----> queue_processed.

处理完所有记录后,我希望得到以下队列状态:

queue_pending1: Pending(0), Enqueued(100), Dequeued(100)
queue_pending2: Pending(0), Enqueued(100), Dequeued(100)
queue_processed: Pending(200), Enqueued(200), Dequeued(0)

但我得到的是:

queue_pending1: Pending(0), Enqueued(100), Dequeued(100)
queue_pending2: Pending(5), Enqueued(100), Dequeued(95)
queue_processed: Pending(200), Enqueued(200), Dequeued(0)

我不明白为什么在queue_pending2中有5条记录未决,所以我检查了process#2的日志。我发现所有100封邮件都在process#2处理。

现在我不明白为什么queue_pending2有待处理的消息为5。

我不知道:

  • 如何修复此问题。
  • 在哪里检查日志或。
  • 至少找到了这个的根本原因。

请帮忙。如果您需要进一步的细节,我会提供。

我在Active MQ 5.8Linux使用默认配置JAVA

以下是我用于Create ConnectionCreate/Connect to QueueSend MessageReceive Message

的方法
/**
     * @throws JMSException
     *             , Exception
     */
    private void setUpActiveMQConnection() throws JMSException {
        connectionFactory = new ActiveMQConnectionFactory(this.activeMQUser,
                this.activeMQPassword, this.activeMQURI);
        try {

            connection = connectionFactory.createConnection();
            connection.start();
                    //transacted = false 
            session = connection.createSession(transacted,
                    Session.AUTO_ACKNOWLEDGE);
            isConnected = true;
        } catch (JMSException e) {
            isConnected = false;
            throw e;
        }
    }

/**
     * @throws Exception
     */
    private void createQueue() throws JMSException {
        try {
            if (destinationQueue == null) {
                destinationQueue = session.createQueue(this.activeMQQueueName);
                isQueueAvailable = true;
            }
        } catch (JMSException e) {
            isQueueAvailable = false;
            throw e;
        } 
    }

    /**
     * @throws JMSException
     * 
     */
    private void createProducer() throws JMSException {
        if (producerForQueue == null) {
            try {
                producerForQueue = session.createProducer(destinationQueue);
                producerForQueue.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
                isProducerAvailable = true;
            } catch (JMSException e) {
                isProducerAvailable = false;
                throw e;
            }
        }
    }

    /**
     * @throws JMSException
     */
    private void createConsumer() throws JMSException {
        if (consumerForQueue == null) {
            try {
                consumerForQueue = session.createConsumer(destinationQueue);
                isConsumerAvailable = true;
            } catch (JMSException e) {
                isConsumerAvailable = false;
                throw e;
            }
        }
    }

/*
 * (non-Javadoc)
 * 
 */
@Override
public void sendMessage(Serializable objectToQueue) throws JMSException {
    ObjectMessage message = session.createObjectMessage();
    message.setObject(objectToQueue);
    producerForQueue.send(message);
}

/*
 * (non-Javadoc)
 * 
 * @see example.jms.impl.JMSConnection#receiveMessage()
 */
@Override
public Serializable receiveMessage() throws JMSException {
    Message message = consumerForQueue.receive(timeout);
    if (message instanceof ObjectMessage) {
        ObjectMessage objMsg = (ObjectMessage) message;
        Serializable sobject = objMsg.getObject();
        return sobject;
    }
    return null;
}

0 个答案:

没有答案