Search in sources :

Example 1 with RedeliveryPolicyMap

use of org.apache.activemq.broker.region.policy.RedeliveryPolicyMap in project activemq-artemis by apache.

the class BrokerRedeliveryTest method startBroker.

private void startBroker(boolean deleteMessages) throws Exception {
    broker = new BrokerService();
    broker.setSchedulerSupport(true);
    RedeliveryPlugin redeliveryPlugin = new RedeliveryPlugin();
    RedeliveryPolicy brokerRedeliveryPolicy = new RedeliveryPolicy();
    brokerRedeliveryPolicy.setRedeliveryDelay(redeliveryDelayMillis);
    brokerRedeliveryPolicy.setInitialRedeliveryDelay(initialRedeliveryDelayMillis);
    brokerRedeliveryPolicy.setMaximumRedeliveries(maxBrokerRedeliveries);
    RedeliveryPolicyMap redeliveryPolicyMap = new RedeliveryPolicyMap();
    redeliveryPolicyMap.setDefaultEntry(brokerRedeliveryPolicy);
    redeliveryPlugin.setRedeliveryPolicyMap(redeliveryPolicyMap);
    broker.setPlugins(new BrokerPlugin[] { redeliveryPlugin });
    if (deleteMessages) {
        broker.setDeleteAllMessagesOnStartup(true);
    }
    broker.start();
}
Also used : RedeliveryPlugin(org.apache.activemq.broker.util.RedeliveryPlugin) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) RedeliveryPolicyMap(org.apache.activemq.broker.region.policy.RedeliveryPolicyMap)

Example 2 with RedeliveryPolicyMap

use of org.apache.activemq.broker.region.policy.RedeliveryPolicyMap in project activemq-artemis by apache.

the class RedeliveryPluginTest method testInstallPluginValidation.

public void testInstallPluginValidation() throws Exception {
    RedeliveryPolicyMap redeliveryPolicyMap = new RedeliveryPolicyMap();
    RedeliveryPolicy defaultEntry = new RedeliveryPolicy();
    defaultEntry.setInitialRedeliveryDelay(500);
    redeliveryPolicyMap.setDefaultEntry(defaultEntry);
    underTest.setRedeliveryPolicyMap(redeliveryPolicyMap);
    final BrokerService brokerService = new BrokerService();
    brokerService.setSchedulerSupport(false);
    Broker broker = new ErrorBroker("hi") {

        @Override
        public BrokerService getBrokerService() {
            return brokerService;
        }
    };
    try {
        underTest.installPlugin(broker);
        fail("expect exception on no scheduler support");
    } catch (Exception expected) {
        LOG.info("expected: " + expected);
    }
    brokerService.setSchedulerSupport(true);
    try {
        underTest.installPlugin(broker);
        fail("expect exception on small initial delay");
    } catch (Exception expected) {
        LOG.info("expected: " + expected);
    }
    defaultEntry.setInitialRedeliveryDelay(5000);
    defaultEntry.setRedeliveryDelay(500);
    brokerService.setSchedulerSupport(true);
    try {
        underTest.installPlugin(broker);
        fail("expect exception on small redelivery delay");
    } catch (Exception expected) {
        LOG.info("expected: " + expected);
    }
}
Also used : Broker(org.apache.activemq.broker.Broker) ErrorBroker(org.apache.activemq.broker.ErrorBroker) ErrorBroker(org.apache.activemq.broker.ErrorBroker) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) RedeliveryPolicyMap(org.apache.activemq.broker.region.policy.RedeliveryPolicyMap) BrokerService(org.apache.activemq.broker.BrokerService)

Example 3 with RedeliveryPolicyMap

use of org.apache.activemq.broker.region.policy.RedeliveryPolicyMap in project activemq-artemis by apache.

the class RedeliveryPolicyTest method testRedeliveryPolicyPerDestination.

@Test
public void testRedeliveryPolicyPerDestination() throws Exception {
    RedeliveryPolicy queuePolicy = new RedeliveryPolicy();
    queuePolicy.setInitialRedeliveryDelay(0);
    queuePolicy.setRedeliveryDelay(1000);
    queuePolicy.setUseExponentialBackOff(false);
    queuePolicy.setMaximumRedeliveries(2);
    RedeliveryPolicy topicPolicy = new RedeliveryPolicy();
    topicPolicy.setInitialRedeliveryDelay(0);
    topicPolicy.setRedeliveryDelay(1000);
    topicPolicy.setUseExponentialBackOff(false);
    topicPolicy.setMaximumRedeliveries(3);
    // Receive a message with the JMS API
    RedeliveryPolicyMap map = connection.getRedeliveryPolicyMap();
    map.put(new ActiveMQTopic(">"), topicPolicy);
    map.put(new ActiveMQQueue(">"), queuePolicy);
    connection.start();
    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue queue = new ActiveMQQueue("TEST");
    ActiveMQTopic topic = new ActiveMQTopic("TEST");
    this.makeSureCoreQueueExist("TEST");
    MessageProducer producer = session.createProducer(null);
    MessageConsumer queueConsumer = session.createConsumer(queue);
    MessageConsumer topicConsumer = session.createConsumer(topic);
    // Send the messages
    producer.send(queue, session.createTextMessage("1st"));
    producer.send(queue, session.createTextMessage("2nd"));
    producer.send(topic, session.createTextMessage("1st"));
    producer.send(topic, session.createTextMessage("2nd"));
    session.commit();
    TextMessage m;
    m = (TextMessage) queueConsumer.receive(100);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) topicConsumer.receive(100);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) queueConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    m = (TextMessage) topicConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    session.rollback();
    m = (TextMessage) queueConsumer.receive(100);
    assertNotNull("first immediate redelivery", m);
    m = (TextMessage) topicConsumer.receive(100);
    assertNotNull("first immediate redelivery", m);
    session.rollback();
    m = (TextMessage) queueConsumer.receive(100);
    assertNull("second delivery delayed: " + m, m);
    m = (TextMessage) topicConsumer.receive(100);
    assertNull("second delivery delayed: " + m, m);
    m = (TextMessage) queueConsumer.receive(2000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) topicConsumer.receive(2000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) queueConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    m = (TextMessage) topicConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    session.rollback();
    m = (TextMessage) queueConsumer.receive(2000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) topicConsumer.receive(2000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) queueConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    m = (TextMessage) topicConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    session.rollback();
    // No third attempt for the Queue consumer
    m = (TextMessage) queueConsumer.receive(2000);
    assertNull(m);
    m = (TextMessage) topicConsumer.receive(2000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) queueConsumer.receive(100);
    assertNull(m);
    m = (TextMessage) topicConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    session.commit();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) RedeliveryPolicyMap(org.apache.activemq.broker.region.policy.RedeliveryPolicyMap) 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 4 with RedeliveryPolicyMap

use of org.apache.activemq.broker.region.policy.RedeliveryPolicyMap in project activemq-artemis by apache.

the class RedeliveryPolicyTest method testRedeliveryPolicyPerDestination.

public void testRedeliveryPolicyPerDestination() throws Exception {
    RedeliveryPolicy queuePolicy = new RedeliveryPolicy();
    queuePolicy.setInitialRedeliveryDelay(0);
    queuePolicy.setRedeliveryDelay(1000);
    queuePolicy.setUseExponentialBackOff(false);
    queuePolicy.setMaximumRedeliveries(2);
    RedeliveryPolicy topicPolicy = new RedeliveryPolicy();
    topicPolicy.setInitialRedeliveryDelay(0);
    topicPolicy.setRedeliveryDelay(1000);
    topicPolicy.setUseExponentialBackOff(false);
    topicPolicy.setMaximumRedeliveries(3);
    // Receive a message with the JMS API
    RedeliveryPolicyMap map = connection.getRedeliveryPolicyMap();
    map.put(new ActiveMQTopic(">"), topicPolicy);
    map.put(new ActiveMQQueue(">"), queuePolicy);
    connection.start();
    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue queue = new ActiveMQQueue("TEST");
    ActiveMQTopic topic = new ActiveMQTopic("TEST");
    MessageProducer producer = session.createProducer(null);
    MessageConsumer queueConsumer = session.createConsumer(queue);
    MessageConsumer topicConsumer = session.createConsumer(topic);
    // Send the messages
    producer.send(queue, session.createTextMessage("1st"));
    producer.send(queue, session.createTextMessage("2nd"));
    producer.send(topic, session.createTextMessage("1st"));
    producer.send(topic, session.createTextMessage("2nd"));
    session.commit();
    TextMessage m;
    m = (TextMessage) queueConsumer.receive(100);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) topicConsumer.receive(100);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) queueConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    m = (TextMessage) topicConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    session.rollback();
    m = (TextMessage) queueConsumer.receive(100);
    assertNotNull("first immediate redelivery", m);
    m = (TextMessage) topicConsumer.receive(100);
    assertNotNull("first immediate redelivery", m);
    session.rollback();
    m = (TextMessage) queueConsumer.receive(100);
    assertNull("second delivery delayed: " + m, m);
    m = (TextMessage) topicConsumer.receive(100);
    assertNull("second delivery delayed: " + m, m);
    m = (TextMessage) queueConsumer.receive(2000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) topicConsumer.receive(2000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) queueConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    m = (TextMessage) topicConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    session.rollback();
    m = (TextMessage) queueConsumer.receive(2000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) topicConsumer.receive(2000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) queueConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    m = (TextMessage) topicConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    session.rollback();
    // No third attempt for the Queue consumer
    m = (TextMessage) queueConsumer.receive(2000);
    assertNull(m);
    m = (TextMessage) topicConsumer.receive(2000);
    assertNotNull(m);
    assertEquals("1st", m.getText());
    m = (TextMessage) queueConsumer.receive(100);
    assertNull(m);
    m = (TextMessage) topicConsumer.receive(100);
    assertNotNull(m);
    assertEquals("2nd", m.getText());
    session.commit();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) RedeliveryPolicyMap(org.apache.activemq.broker.region.policy.RedeliveryPolicyMap) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Session(javax.jms.Session) ServerSession(javax.jms.ServerSession)

Aggregations

RedeliveryPolicyMap (org.apache.activemq.broker.region.policy.RedeliveryPolicyMap)4 RedeliveryPolicy (org.apache.activemq.RedeliveryPolicy)3 MessageConsumer (javax.jms.MessageConsumer)2 MessageProducer (javax.jms.MessageProducer)2 Session (javax.jms.Session)2 TextMessage (javax.jms.TextMessage)2 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)2 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)2 ServerSession (javax.jms.ServerSession)1 BasicOpenWireTest (org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest)1 Broker (org.apache.activemq.broker.Broker)1 BrokerService (org.apache.activemq.broker.BrokerService)1 ErrorBroker (org.apache.activemq.broker.ErrorBroker)1 RedeliveryPlugin (org.apache.activemq.broker.util.RedeliveryPlugin)1 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)1 Test (org.junit.Test)1