https://issues.apache.org/jira/browse/AMQ-5476 - fix and test - https://issues.apache.org/jira/browse/AMQ-2790 - default messagePrioritySupported=false
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/bbb2acca Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/bbb2acca Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/bbb2acca Branch: refs/heads/trunk Commit: bbb2acca2fe75ce3b40f6d1092440355ae148610 Parents: a876a34 Author: gtully <gary.tu...@gmail.com> Authored: Fri Dec 5 14:49:48 2014 +0000 Committer: gtully <gary.tu...@gmail.com> Committed: Fri Dec 5 14:49:48 2014 +0000 ---------------------------------------------------------------------- .../org/apache/activemq/ActiveMQConnection.java | 2 +- .../activemq/ActiveMQMessageConsumer.java | 4 +- .../BatchedMessagePriorityConsumerTest.java | 81 ++++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/bbb2acca/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java ---------------------------------------------------------------------- diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java index ed926a1..ed0dd47 100755 --- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java +++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java @@ -204,7 +204,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon protected AtomicInteger transportInterruptionProcessingComplete = new AtomicInteger(0); private long consumerFailoverRedeliveryWaitPeriod; private Scheduler scheduler; - private boolean messagePrioritySupported = true; + private boolean messagePrioritySupported = false; private boolean transactedIndividualAck = false; private boolean nonBlockingRedelivery = false; private boolean rmIdFromConnectionId = false; http://git-wip-us.apache.org/repos/asf/activemq/blob/bbb2acca/activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java ---------------------------------------------------------------------- diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java index 02dbf49..f43b56d 100755 --- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java +++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java @@ -267,7 +267,9 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC this.info.setOptimizedAcknowledge(this.optimizeAcknowledge); this.failoverRedeliveryWaitPeriod = session.connection.getConsumerFailoverRedeliveryWaitPeriod(); this.nonBlockingRedelivery = session.connection.isNonBlockingRedelivery(); - this.transactedIndividualAck = session.connection.isTransactedIndividualAck() || this.nonBlockingRedelivery; + this.transactedIndividualAck = session.connection.isTransactedIndividualAck() + || this.nonBlockingRedelivery + || session.connection.isMessagePrioritySupported(); this.consumerExpiryCheckEnabled = session.connection.isConsumerExpiryCheckEnabled(); if (messageListener != null) { setMessageListener(messageListener); http://git-wip-us.apache.org/repos/asf/activemq/blob/bbb2acca/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/BatchedMessagePriorityConsumerTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/BatchedMessagePriorityConsumerTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/BatchedMessagePriorityConsumerTest.java new file mode 100644 index 0000000..16e2ac2 --- /dev/null +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/BatchedMessagePriorityConsumerTest.java @@ -0,0 +1,81 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.usecases; + +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import org.apache.activemq.JmsTestSupport; +import org.apache.activemq.command.ActiveMQDestination; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BatchedMessagePriorityConsumerTest extends JmsTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(BatchedMessagePriorityConsumerTest.class); + + public void testBatchWithLowPriorityFirstAndClientSupport() throws Exception { + doTestBatchWithLowPriorityFirst(true); + } + + public void testBatchWithLowPriorityFirstAndClientSupportOff() throws Exception { + doTestBatchWithLowPriorityFirst(false); + } + + public void doTestBatchWithLowPriorityFirst(boolean clientPrioritySupport) throws Exception { + + connection.start(); + connection.setMessagePrioritySupported(clientPrioritySupport); + + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE); + + + MessageProducer producer = session.createProducer(destination); + producer.setPriority(0); + sendMessages(session, producer, 2); + producer.close(); + + MessageProducer producer2 = session.createProducer(destination); + producer2.setPriority(9); + sendMessages(session, producer2, 3); + producer2.close(); + + session.close(); + + Session consumerSession = connection.createSession(true, Session.SESSION_TRANSACTED); + MessageConsumer messageConsumer = consumerSession.createConsumer(destination); + + for (int i = 0; i < 5; i++) { + Message message = messageConsumer.receive(4000); + LOG.info("MessageID: " + message.getJMSMessageID()); + } + + consumerSession.commit(); + consumerSession.close(); + + // should be nothing left + consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + messageConsumer = consumerSession.createConsumer(destination); + + assertNull("No message left", messageConsumer.receive(1000)); + + consumerSession.close(); + + } +} \ No newline at end of file