Search in sources :

Example 21 with RedeliveryPolicy

use of org.apache.activemq.RedeliveryPolicy in project activemq-artemis by apache.

the class NoRetryDeadLetterTest method createConnectionFactory.

@Override
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
    ActiveMQConnectionFactory connectionFactory = super.createConnectionFactory();
    RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
    redeliveryPolicy.setMaximumRedeliveries(0);
    connectionFactory.setRedeliveryPolicy(redeliveryPolicy);
    return connectionFactory;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy)

Example 22 with RedeliveryPolicy

use of org.apache.activemq.RedeliveryPolicy in project activemq-artemis by apache.

the class RedeliveryPolicyTest method testDLQHandling.

/**
 * @throws Exception
 */
@Test
public void testDLQHandling() throws Exception {
    this.makeSureCoreQueueExist("ActiveMQ.DLQ");
    // Receive a message with the JMS API
    RedeliveryPolicy policy = connection.getRedeliveryPolicy();
    policy.setInitialRedeliveryDelay(100);
    policy.setUseExponentialBackOff(false);
    policy.setMaximumRedeliveries(2);
    connection.start();
    Session session = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
    ActiveMQQueue destination = new ActiveMQQueue("TEST");
    this.makeSureCoreQueueExist("TEST");
    MessageProducer producer = session.createProducer(destination);
    MessageConsumer consumer = session.createConsumer(destination);
    MessageConsumer dlqConsumer = session.createConsumer(new ActiveMQQueue("ActiveMQ.DLQ"));
    // Send the messages
    producer.send(session.createTextMessage("1st"));
    producer.send(session.createTextMessage("2nd"));
    session.commit();
    TextMessage m;
    m = (TextMessage) consumer.receive(1000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    session.rollback();
    m = (TextMessage) consumer.receive(1000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    session.rollback();
    m = (TextMessage) consumer.receive(2000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    session.rollback();
    // The last rollback should cause the 1st message to get sent to the DLQ
    m = (TextMessage) consumer.receive(1000);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    session.commit();
    // We should be able to get the message off the DLQ now.
    m = (TextMessage) dlqConsumer.receive(1000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    String cause = m.getStringProperty(ActiveMQMessage.DLQ_DELIVERY_FAILURE_CAUSE_PROPERTY);
    assertTrue("cause exception has policy ref", cause.contains("RedeliveryPolicy"));
    session.commit();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) BasicOpenWireTest(org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest) Test(org.junit.Test)

Example 23 with RedeliveryPolicy

use of org.apache.activemq.RedeliveryPolicy in project activemq-artemis by apache.

the class RedeliveryPolicyTest method testInitialRedeliveryDelayZero.

@Test
public void testInitialRedeliveryDelayZero() throws Exception {
    // Receive a message with the JMS API
    RedeliveryPolicy policy = connection.getRedeliveryPolicy();
    policy.setInitialRedeliveryDelay(0);
    policy.setUseExponentialBackOff(false);
    policy.setMaximumRedeliveries(1);
    connection.start();
    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue destination = new ActiveMQQueue("TEST");
    this.makeSureCoreQueueExist("TEST");
    MessageProducer producer = session.createProducer(destination);
    MessageConsumer consumer = session.createConsumer(destination);
    // Send the messages
    producer.send(session.createTextMessage("1st"));
    producer.send(session.createTextMessage("2nd"));
    session.commit();
    TextMessage m;
    m = (TextMessage) consumer.receive(100);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    session.rollback();
    m = (TextMessage) consumer.receive(100);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) consumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    session.commit();
    session.commit();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) BasicOpenWireTest(org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest) Test(org.junit.Test)

Example 24 with RedeliveryPolicy

use of org.apache.activemq.RedeliveryPolicy in project activemq-artemis by apache.

the class RedeliveryPolicyTest method testExponentialRedeliveryPolicyDelaysDeliveryOnRollback.

/**
 * @throws Exception
 */
@Test
public void testExponentialRedeliveryPolicyDelaysDeliveryOnRollback() throws Exception {
    // Receive a message with the JMS API
    RedeliveryPolicy policy = connection.getRedeliveryPolicy();
    policy.setInitialRedeliveryDelay(0);
    policy.setRedeliveryDelay(500);
    policy.setBackOffMultiplier((short) 2);
    policy.setUseExponentialBackOff(true);
    connection.start();
    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue destination = new ActiveMQQueue("testExponentialRedeliveryPolicyDelaysDeliveryOnRollback");
    this.makeSureCoreQueueExist("testExponentialRedeliveryPolicyDelaysDeliveryOnRollback");
    MessageProducer producer = session.createProducer(destination);
    MessageConsumer consumer = session.createConsumer(destination);
    // Send the messages
    producer.send(session.createTextMessage("1st"));
    producer.send(session.createTextMessage("2nd"));
    session.commit();
    TextMessage m;
    m = (TextMessage) consumer.receive(1000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    session.rollback();
    // No delay on first rollback..
    m = (TextMessage) consumer.receive(100);
    assertNotNull(m);
    session.rollback();
    // Show subsequent re-delivery delay is incrementing.
    m = (TextMessage) consumer.receive(100);
    assertNull(m);
    m = (TextMessage) consumer.receive(700);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    session.rollback();
    // Show re-delivery delay is incrementing exponentially
    m = (TextMessage) consumer.receive(100);
    assertNull(m);
    m = (TextMessage) consumer.receive(500);
    assertNull(m);
    m = (TextMessage) consumer.receive(700);
    assertNotNull(m);
    assertEquals("1st", m.getText());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) BasicOpenWireTest(org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest) Test(org.junit.Test)

Example 25 with RedeliveryPolicy

use of org.apache.activemq.RedeliveryPolicy in project activemq-artemis by apache.

the class RedeliveryPolicyTest method testRedeliveryDelayOne.

@Test
public void testRedeliveryDelayOne() throws Exception {
    // Receive a message with the JMS API
    RedeliveryPolicy policy = connection.getRedeliveryPolicy();
    policy.setInitialRedeliveryDelay(0);
    policy.setRedeliveryDelay(1000);
    policy.setUseExponentialBackOff(false);
    policy.setMaximumRedeliveries(2);
    connection.start();
    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue destination = new ActiveMQQueue("TEST");
    this.makeSureCoreQueueExist("TEST");
    MessageProducer producer = session.createProducer(destination);
    MessageConsumer consumer = session.createConsumer(destination);
    // Send the messages
    producer.send(session.createTextMessage("1st"));
    producer.send(session.createTextMessage("2nd"));
    session.commit();
    TextMessage m;
    m = (TextMessage) consumer.receive(100);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    session.rollback();
    m = (TextMessage) consumer.receive(100);
    assertNotNull("first immediate redelivery", m);
    session.rollback();
    m = (TextMessage) consumer.receive(100);
    assertNull("second delivery delayed: " + m, m);
    m = (TextMessage) consumer.receive(2000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) consumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    session.commit();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) BasicOpenWireTest(org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest) Test(org.junit.Test)

Aggregations

RedeliveryPolicy (org.apache.activemq.RedeliveryPolicy)30 MessageConsumer (javax.jms.MessageConsumer)11 Session (javax.jms.Session)11 BasicOpenWireTest (org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest)11 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)11 Test (org.junit.Test)11 MessageProducer (javax.jms.MessageProducer)10 TextMessage (javax.jms.TextMessage)10 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)9 Bean (org.springframework.context.annotation.Bean)4 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)3 RedeliveryPolicyMap (org.apache.activemq.broker.region.policy.RedeliveryPolicyMap)3 BrokerService (org.apache.activemq.broker.BrokerService)2 PooledConnectionFactory (org.apache.activemq.pool.PooledConnectionFactory)2 Message (javax.jms.Message)1 Broker (org.apache.activemq.broker.Broker)1 ErrorBroker (org.apache.activemq.broker.ErrorBroker)1 RedeliveryPlugin (org.apache.activemq.broker.util.RedeliveryPlugin)1 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)1 PooledConnectionFactory (org.apache.activemq.jms.pool.PooledConnectionFactory)1