mirror of https://github.com/apache/activemq.git
Ensure that the redelivery policy is never null in the consumer.
(cherry picked from commit 9287055338
)
This commit is contained in:
parent
b04cfeb8af
commit
b32be1bb11
|
@ -40,7 +40,20 @@ import javax.jms.MessageListener;
|
||||||
import javax.jms.TransactionRolledBackException;
|
import javax.jms.TransactionRolledBackException;
|
||||||
|
|
||||||
import org.apache.activemq.blob.BlobDownloader;
|
import org.apache.activemq.blob.BlobDownloader;
|
||||||
import org.apache.activemq.command.*;
|
import org.apache.activemq.command.ActiveMQBlobMessage;
|
||||||
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
|
import org.apache.activemq.command.ActiveMQMessage;
|
||||||
|
import org.apache.activemq.command.ActiveMQObjectMessage;
|
||||||
|
import org.apache.activemq.command.ActiveMQTempDestination;
|
||||||
|
import org.apache.activemq.command.CommandTypes;
|
||||||
|
import org.apache.activemq.command.ConsumerId;
|
||||||
|
import org.apache.activemq.command.ConsumerInfo;
|
||||||
|
import org.apache.activemq.command.MessageAck;
|
||||||
|
import org.apache.activemq.command.MessageDispatch;
|
||||||
|
import org.apache.activemq.command.MessageId;
|
||||||
|
import org.apache.activemq.command.MessagePull;
|
||||||
|
import org.apache.activemq.command.RemoveInfo;
|
||||||
|
import org.apache.activemq.command.TransactionId;
|
||||||
import org.apache.activemq.management.JMSConsumerStatsImpl;
|
import org.apache.activemq.management.JMSConsumerStatsImpl;
|
||||||
import org.apache.activemq.management.StatsCapable;
|
import org.apache.activemq.management.StatsCapable;
|
||||||
import org.apache.activemq.management.StatsImpl;
|
import org.apache.activemq.management.StatsImpl;
|
||||||
|
@ -199,6 +212,9 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
|
||||||
|
|
||||||
this.session = session;
|
this.session = session;
|
||||||
this.redeliveryPolicy = session.connection.getRedeliveryPolicyMap().getEntryFor(dest);
|
this.redeliveryPolicy = session.connection.getRedeliveryPolicyMap().getEntryFor(dest);
|
||||||
|
if (this.redeliveryPolicy == null) {
|
||||||
|
this.redeliveryPolicy = new RedeliveryPolicy();
|
||||||
|
}
|
||||||
setTransformer(session.getTransformer());
|
setTransformer(session.getTransformer());
|
||||||
|
|
||||||
this.info = new ConsumerInfo(consumerId);
|
this.info = new ConsumerInfo(consumerId);
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/**
|
||||||
|
* 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.bugs;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import javax.jms.Connection;
|
||||||
|
import javax.jms.Message;
|
||||||
|
import javax.jms.MessageConsumer;
|
||||||
|
import javax.jms.MessageProducer;
|
||||||
|
import javax.jms.Queue;
|
||||||
|
import javax.jms.Session;
|
||||||
|
|
||||||
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
|
import org.apache.activemq.broker.BrokerService;
|
||||||
|
import org.apache.activemq.broker.region.policy.RedeliveryPolicyMap;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class AMQ6125Test {
|
||||||
|
|
||||||
|
private BrokerService broker;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
broker = new BrokerService();
|
||||||
|
broker.setPersistent(false);
|
||||||
|
broker.setUseJmx(false);
|
||||||
|
broker.start();
|
||||||
|
broker.waitUntilStarted();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
if (broker != null) {
|
||||||
|
broker.stop();
|
||||||
|
broker.waitUntilStopped();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRollbackWithNoPolicy() throws Exception {
|
||||||
|
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(broker.getVmConnectorURI());
|
||||||
|
cf.setRedeliveryPolicyMap(new RedeliveryPolicyMap());
|
||||||
|
Connection connection = cf.createConnection();
|
||||||
|
connection.start();
|
||||||
|
|
||||||
|
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
|
||||||
|
Queue queue = session.createTemporaryQueue();
|
||||||
|
MessageProducer producer = session.createProducer(queue);
|
||||||
|
|
||||||
|
producer.send(session.createMessage());
|
||||||
|
session.commit();
|
||||||
|
|
||||||
|
MessageConsumer consumer = session.createConsumer(queue);
|
||||||
|
Message message = consumer.receive(2000);
|
||||||
|
|
||||||
|
assertNotNull(message);
|
||||||
|
|
||||||
|
session.rollback();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue