我有queue_pending1
和queue_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.8
上Linux
使用默认配置JAVA
。
以下是我用于Create Connection
,Create/Connect to Queue
,Send Message
,Receive 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;
}