Search in sources :

Example 26 with RedeliveryPolicy

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();
}
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 27 with RedeliveryPolicy

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;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) Bean(org.springframework.context.annotation.Bean)

Example 28 with RedeliveryPolicy

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;
}
Also used : RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy)

Example 29 with 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;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) PooledConnectionFactory(org.apache.activemq.jms.pool.PooledConnectionFactory)

Example 30 with RedeliveryPolicy

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);
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy)

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