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;
}
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();
}
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();
}
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);
}
}
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());
}
Aggregations