use of org.apache.activemq.RedeliveryPolicy in project activemq-artemis by apache.
the class RedeliveryPolicyTest method testInitialRedeliveryDelayOne.
@Test
public void testInitialRedeliveryDelayOne() throws Exception {
// Receive a message with the JMS API
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
policy.setInitialRedeliveryDelay(1000);
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);
assertNull(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();
}
use of org.apache.activemq.RedeliveryPolicy in project kylo by Teradata.
the class ActiveMqConfig method connectionFactory.
@Bean(name = "activemqConnectionPool")
public ConnectionFactory connectionFactory() {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(env.getProperty("jms.activemq.broker.url"));
factory.setTrustAllPackages(true);
factory.setRedeliveryPolicy(new RedeliveryPolicy());
factory.getRedeliveryPolicy().setMaximumRedeliveries(env.getProperty("jms.maximumRedeliveries", Integer.class, 100));
factory.getRedeliveryPolicy().setRedeliveryDelay(env.getProperty("jms.redeliveryDelay", Long.class, 1000L));
factory.getRedeliveryPolicy().setInitialRedeliveryDelay(env.getProperty("jms.initialRedeliveryDelay", Long.class, 1000L));
// try for 10 min
factory.getRedeliveryPolicy().setMaximumRedeliveryDelay(env.getProperty("jms.maximumRedeliveryDelay", Long.class, 600000L));
factory.getRedeliveryPolicy().setBackOffMultiplier(env.getProperty("jms.backOffMultiplier", Double.class, 5d));
factory.getRedeliveryPolicy().setUseExponentialBackOff(env.getProperty("jms.useExponentialBackOff", Boolean.class, false));
PooledConnectionFactory pool = new PooledConnectionFactory();
pool.setIdleTimeout(0);
pool.setConnectionFactory(getCredentialsAdapter(factory));
log.info("Setup ActiveMQ ConnectionFactory for " + env.getProperty("jms.activemq.broker.url"));
return pool;
}
use of org.apache.activemq.RedeliveryPolicy in project cxf by apache.
the class MessageListenerTest method redeliveryPolicy.
private static RedeliveryPolicy redeliveryPolicy() {
RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
redeliveryPolicy.setRedeliveryDelay(500L);
redeliveryPolicy.setMaximumRedeliveries(1);
return redeliveryPolicy;
}
use of org.apache.activemq.RedeliveryPolicy in project tesb-rt-se by Talend.
the class ImporterTest method createConnectionFactory.
private PooledConnectionFactory createConnectionFactory() {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("localhost:61616");
RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
redeliveryPolicy.setMaximumRedeliveries(2);
connectionFactory.setRedeliveryPolicy(redeliveryPolicy);
PooledConnectionFactory pooled = new PooledConnectionFactory();
pooled.setConnectionFactory(connectionFactory);
return pooled;
}
use of org.apache.activemq.RedeliveryPolicy in project main by JohnPeng739.
the class ReceiveSpanRegionCommandSpout method initJmxConnection.
// 初始化并连接JMS服务器
private void initJmxConnection() {
ConnectionFactory factory = new ActiveMQConnectionFactory(jmxUser, jmxPassword, jmxUrl);
try {
jmsConnection = factory.createConnection();
jmsConnection.start();
jssSession = jmsConnection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
if (jmsConnection instanceof ActiveMQConnection) {
// 设置重试次数
RedeliveryPolicy policy = ((ActiveMQConnection) jmsConnection).getRedeliveryPolicy();
policy.setMaximumRedeliveries((int) retryNum);
((ActiveMQConnection) jmsConnection).setRedeliveryPolicy(policy);
}
Destination dest = jssSession.createQueue(jmxQueue);
jmsConsumer = jssSession.createConsumer(dest);
if (logger.isInfoEnabled()) {
logger.info("init message client success.");
}
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("init message client fail.", ex);
}
}
}
Aggregations