Search in sources :

Example 11 with PooledConnectionFactory

use of org.apache.activemq.pool.PooledConnectionFactory in project jim-framework by jiangmin168168.

the class ProducerConnctionFactory method create.

public PooledConnectionFactory create(String brokerClusterUrl) {
    ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory();
    mqConnectionFactory.setBrokerURL(brokerClusterUrl);
    mqConnectionFactory.setTransportListener(this);
    // mqConnectionFactory.
    PooledConnectionFactory connectionFactory = new JimPooledConnectionFactory(mqConnectionFactory);
    connectionFactory.setMaxConnections(10);
    connectionFactory.setTimeBetweenExpirationCheckMillis(1000);
    return connectionFactory;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory)

Example 12 with PooledConnectionFactory

use of org.apache.activemq.pool.PooledConnectionFactory in project jim-framework by jiangmin168168.

the class ConnectionFactoryContainer method stopProducerConnectionFactory.

public static void stopProducerConnectionFactory() {
    for (Map.Entry<String, PooledConnectionFactory> entry : producerConnectionFactoryMap.entrySet()) {
        PooledConnectionFactory pooledConnectionFactory = entry.getValue();
        if (null != pooledConnectionFactory) {
            // pooledConnectionFactory.stop();
            needToRemoveConnctionFactories.add(pooledConnectionFactory);
            producerConnectionFactoryMap.remove(entry.getKey());
        }
    }
}
Also used : PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 13 with PooledConnectionFactory

use of org.apache.activemq.pool.PooledConnectionFactory in project jim-framework by jiangmin168168.

the class ConnectionFactoryContainer method createPooledConnectionFactory.

public static PooledConnectionFactory createPooledConnectionFactory(String brokerUrl) {
    final String brokerClusterUrl = brokerUrl.replace(";", ",");
    PooledConnectionFactory connectionFactory = null;
    // ((ActiveMQConnectionFactory)connectionFactory.getConnectionFactory()).get;
    synchronized (lock) {
        if (producerConnectionFactoryMap.containsKey(brokerClusterUrl)) {
            connectionFactory = producerConnectionFactoryMap.get(brokerClusterUrl);
            needToRemoveConnctionFactories.add(connectionFactory);
            producerConnectionFactoryMap.remove(brokerUrl);
        }
        ProducerConnctionFactory producerConnctionFactory = new ProducerConnctionFactory();
        // producerConnctionFactory.init();
        connectionFactory = producerConnctionFactory.create(brokerClusterUrl);
        producerConnectionFactoryMap.put(brokerClusterUrl, connectionFactory);
        return connectionFactory;
    }
}
Also used : PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) ProducerConnctionFactory(com.jim.framework.activemq.producer.ProducerConnctionFactory)

Example 14 with PooledConnectionFactory

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

the class ApplicationAuditLogger method tryToEstablishJMSConnectionImpl.

private boolean tryToEstablishJMSConnectionImpl() {
    Set<String> jmsBrokerURISet = appConfiguration.getJmsBrokerURISet();
    if (!enabled || CollectionUtils.isEmpty(jmsBrokerURISet)) {
        return false;
    }
    this.jmsBrokerURISet = new HashSet<String>(jmsBrokerURISet);
    this.jmsUserName = appConfiguration.getJmsUserName();
    this.jmsPassword = appConfiguration.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 15 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);
    connectionFactory.setTrustAllPackages(true);
    // 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