Search in sources :

Example 16 with PooledConnectionFactory

use of org.apache.activemq.pool.PooledConnectionFactory in project oxAuth by GluuFederation.

the class ApplicationAuditLogger method tryToEstablishJMSConnectionImpl.

private boolean tryToEstablishJMSConnectionImpl() {
    destroy();
    Set<String> jmsBrokerURISet = getJmsBrokerURISet();
    if (BooleanUtils.isNotTrue(isEnabledOAuthAuditnLogging()) || CollectionUtils.isEmpty(jmsBrokerURISet))
        return false;
    this.jmsBrokerURISet = new HashSet<String>(jmsBrokerURISet);
    this.jmsUserName = getJmsUserName();
    this.jmsPassword = getJmsPassword();
    Iterator<String> jmsBrokerURIIterator = jmsBrokerURISet.iterator();
    StringBuilder uriBuilder = new StringBuilder();
    while (jmsBrokerURIIterator.hasNext()) {
        String jmsBrokerURI = jmsBrokerURIIterator.next();
        uriBuilder.append("tcp://");
        uriBuilder.append(jmsBrokerURI);
        if (jmsBrokerURIIterator.hasNext())
            uriBuilder.append(",");
    }
    String brokerUrl = BROKER_URL_PREFIX + uriBuilder + BROKER_URL_SUFFIX;
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(this.jmsUserName, this.jmsPassword, brokerUrl);
    this.pooledConnectionFactory = new PooledConnectionFactory(connectionFactory);
    pooledConnectionFactory.setIdleTimeout(5000);
    pooledConnectionFactory.setMaxConnections(10);
    pooledConnectionFactory.start();
    return true;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory)

Example 17 with PooledConnectionFactory

use of org.apache.activemq.pool.PooledConnectionFactory in project sling by apache.

the class ActiveMQConnectionFactoryService method activate.

@Activate
public void activate(Config config) {
    pooledConnectionFactory = new PooledConnectionFactory(config.jms_brokerUri());
    pooledConnectionFactory.start();
}
Also used : PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) Activate(org.osgi.service.component.annotations.Activate)

Example 18 with PooledConnectionFactory

use of org.apache.activemq.pool.PooledConnectionFactory 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 19 with PooledConnectionFactory

use of org.apache.activemq.pool.PooledConnectionFactory in project camel by apache.

the class CamelJmsTestHelper method createConnectionFactory.

public static ConnectionFactory createConnectionFactory(String options) {
    // using a unique broker name improves testing when running the entire test suite in the same JVM
    int id = counter.incrementAndGet();
    String url = "vm://test-broker-" + id + "?broker.persistent=false&broker.useJmx=false";
    if (options != null) {
        url = url + "&" + options;
    }
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
    // optimize AMQ to be as fast as possible so unit testing is quicker
    connectionFactory.setCopyMessageOnSend(false);
    connectionFactory.setOptimizeAcknowledge(true);
    connectionFactory.setOptimizedMessageDispatch(true);
    // When using asyncSend, producers will not be guaranteed to send in the order we
    // have in the tests (which may be confusing for queues) so we need this set to false.
    // Another way of guaranteeing order is to use persistent messages or transactions.
    connectionFactory.setUseAsyncSend(false);
    connectionFactory.setAlwaysSessionAsync(false);
    // use a pooled connection factory
    PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory);
    pooled.setMaxConnections(8);
    return pooled;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory)

Example 20 with PooledConnectionFactory

use of org.apache.activemq.pool.PooledConnectionFactory in project camel by apache.

the class CamelJmsTestHelper method createPersistentConnectionFactory.

public static ConnectionFactory createPersistentConnectionFactory(String options) {
    // using a unique broker name improves testing when running the entire test suite in the same JVM
    int id = counter.incrementAndGet();
    // use an unique data directory in target
    String dir = "target/activemq-data-" + id;
    // remove dir so its empty on startup
    FileUtil.removeDir(new File(dir));
    String url = "vm://test-broker-" + id + "?broker.persistent=true&broker.useJmx=false&broker.dataDirectory=" + dir;
    if (options != null) {
        url = url + "&" + options;
    }
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
    // optimize AMQ to be as fast as possible so unit testing is quicker
    connectionFactory.setCopyMessageOnSend(false);
    connectionFactory.setOptimizeAcknowledge(true);
    connectionFactory.setOptimizedMessageDispatch(true);
    connectionFactory.setUseAsyncSend(true);
    connectionFactory.setAlwaysSessionAsync(false);
    // use a pooled connection factory
    PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory);
    pooled.setMaxConnections(8);
    return pooled;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) File(java.io.File)

Aggregations

PooledConnectionFactory (org.apache.activemq.pool.PooledConnectionFactory)29 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)18 Test (org.junit.Test)5 Map (java.util.Map)4 JmsTemplate (org.springframework.jms.core.JmsTemplate)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConnectionFactory (javax.jms.ConnectionFactory)3 ConnectionFactoryFeature (org.apache.cxf.transport.jms.ConnectionFactoryFeature)3 ProducerConnctionFactory (com.jim.framework.activemq.producer.ProducerConnctionFactory)2 File (java.io.File)2 RedeliveryPolicy (org.apache.activemq.RedeliveryPolicy)2 EndpointImpl (org.apache.cxf.jaxws.EndpointImpl)2 BeforeClass (org.junit.BeforeClass)2 ConsumerConnctionFactory (com.jim.framework.activemq.producer.ConsumerConnctionFactory)1 JimPooledConnectionFactory (com.jim.framework.activemq.producer.JimPooledConnectionFactory)1 List (java.util.List)1 PostConstruct (javax.annotation.PostConstruct)1 Connection (javax.jms.Connection)1 JMSException (javax.jms.JMSException)1 SOAPBinding (javax.xml.ws.soap.SOAPBinding)1