Search in sources :

Example 1 with RedeliveryPolicy

use of org.apache.activemq.RedeliveryPolicy in project Protocol-Adapter-OSLP by OSGP.

the class MessagingConfig method defaultRedeliveryPolicy.

// === JMS SETTINGS ===
@Override
@Bean
public RedeliveryPolicy defaultRedeliveryPolicy() {
    final RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
    redeliveryPolicy.setInitialRedeliveryDelay(Long.parseLong(this.environment.getRequiredProperty(PROPERTY_NAME_JMS_DEFAULT_INITIAL_REDELIVERY_DELAY)));
    redeliveryPolicy.setMaximumRedeliveries(Integer.parseInt(this.environment.getRequiredProperty(PROPERTY_NAME_JMS_DEFAULT_MAXIMUM_REDELIVERIES)));
    redeliveryPolicy.setMaximumRedeliveryDelay(Long.parseLong(this.environment.getRequiredProperty(PROPERTY_NAME_JMS_DEFAULT_MAXIMUM_REDELIVERY_DELAY)));
    redeliveryPolicy.setRedeliveryDelay(Long.parseLong(this.environment.getRequiredProperty(PROPERTY_NAME_JMS_DEFAULT_REDELIVERY_DELAY)));
    redeliveryPolicy.setBackOffMultiplier(Double.parseDouble(this.environment.getRequiredProperty(PROPERTY_NAME_JMS_DEFAULT_BACK_OFF_MULTIPLIER)));
    redeliveryPolicy.setUseExponentialBackOff(Boolean.parseBoolean(this.environment.getRequiredProperty(PROPERTY_NAME_JMS_DEFAULT_USE_EXPONENTIAL_BACK_OFF)));
    return redeliveryPolicy;
}
Also used : RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) Bean(org.springframework.context.annotation.Bean)

Example 2 with RedeliveryPolicy

use of org.apache.activemq.RedeliveryPolicy 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 3 with RedeliveryPolicy

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

the class BrokerRedeliveryTest method doTestScheduledRedelivery.

public void doTestScheduledRedelivery(int maxBrokerRedeliveriesToValidate, boolean validateDLQ) throws Exception {
    startBroker(true);
    sendMessage(0);
    ActiveMQConnection consumerConnection = (ActiveMQConnection) createConnection();
    RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
    redeliveryPolicy.setInitialRedeliveryDelay(0);
    redeliveryPolicy.setMaximumRedeliveries(0);
    consumerConnection.setRedeliveryPolicy(redeliveryPolicy);
    consumerConnection.start();
    Session consumerSession = consumerConnection.createSession(true, Session.SESSION_TRANSACTED);
    MessageConsumer consumer = consumerSession.createConsumer(destination);
    Message message = consumer.receive(1000);
    assertNotNull("got message", message);
    LOG.info("got: " + message);
    consumerSession.rollback();
    for (int i = 0; i < maxBrokerRedeliveriesToValidate; i++) {
        Message shouldBeNull = consumer.receive(500);
        assertNull("did not get message after redelivery count exceeded: " + shouldBeNull, shouldBeNull);
        TimeUnit.SECONDS.sleep(3);
        Message brokerRedeliveryMessage = consumer.receive(500);
        LOG.info("got: " + brokerRedeliveryMessage);
        assertNotNull("got message via broker redelivery after delay", brokerRedeliveryMessage);
        assertEquals("message matches", message.getStringProperty("data"), brokerRedeliveryMessage.getStringProperty("data"));
        assertEquals("has expiryDelay specified", i == 0 ? initialRedeliveryDelayMillis : redeliveryDelayMillis, brokerRedeliveryMessage.getLongProperty(RedeliveryPlugin.REDELIVERY_DELAY));
        consumerSession.rollback();
    }
    if (validateDLQ) {
        MessageConsumer dlqConsumer = consumerSession.createConsumer(new ActiveMQQueue(SharedDeadLetterStrategy.DEFAULT_DEAD_LETTER_QUEUE_NAME));
        Message dlqMessage = dlqConsumer.receive(2000);
        assertNotNull("Got message from dql", dlqMessage);
        assertEquals("message matches", message.getStringProperty("data"), dlqMessage.getStringProperty("data"));
        consumerSession.commit();
    } else {
        // consume/commit ok
        message = consumer.receive(3000);
        assertNotNull("got message", message);
        assertEquals("redeliveries accounted for", maxBrokerRedeliveriesToValidate + 2, message.getLongProperty("JMSXDeliveryCount"));
        consumerSession.commit();
    }
    consumerConnection.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Session(javax.jms.Session)

Example 4 with RedeliveryPolicy

use of org.apache.activemq.RedeliveryPolicy 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 5 with RedeliveryPolicy

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

the class RedeliveryPolicyTest method testNornalRedeliveryPolicyDelaysDeliveryOnRollback.

/**
 * @throws Exception
 */
@Test
public void testNornalRedeliveryPolicyDelaysDeliveryOnRollback() throws Exception {
    // Receive a message with the JMS API
    RedeliveryPolicy policy = connection.getRedeliveryPolicy();
    policy.setInitialRedeliveryDelay(0);
    policy.setRedeliveryDelay(500);
    connection.start();
    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue destination = new ActiveMQQueue("testNornalRedeliveryPolicyDelaysDeliveryOnRollback");
    this.makeSureCoreQueueExist("testNornalRedeliveryPolicyDelaysDeliveryOnRollback");
    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();
    // The message gets redelivered after 500 ms every time since
    // we are not using exponential backoff.
    m = (TextMessage) consumer.receive(100);
    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)

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