Search in sources :

Example 1 with PooledConnectionFactory

use of org.apache.activemq.pool.PooledConnectionFactory in project spring-boot by spring-projects.

the class JmsAutoConfigurationTests method testActiveMQOverriddenPool.

@Test
public void testActiveMQOverriddenPool() {
    load(TestConfiguration.class, "spring.activemq.pool.enabled:true");
    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    PooledConnectionFactory pool = this.context.getBean(PooledConnectionFactory.class);
    assertThat(jmsTemplate).isNotNull();
    assertThat(pool).isNotNull();
    assertThat(pool).isEqualTo(jmsTemplate.getConnectionFactory());
    ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory();
    assertThat(factory.getBrokerURL()).isEqualTo(ACTIVEMQ_EMBEDDED_URL);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) Test(org.junit.Test)

Example 2 with PooledConnectionFactory

use of org.apache.activemq.pool.PooledConnectionFactory in project spring-boot by spring-projects.

the class JmsAutoConfigurationTests method testActiveMQOverriddenPoolAndRemoteServer.

@Test
public void testActiveMQOverriddenPoolAndRemoteServer() {
    load(TestConfiguration.class, "spring.activemq.pool.enabled:true", "spring.activemq.brokerUrl:tcp://remote-host:10000");
    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    PooledConnectionFactory pool = this.context.getBean(PooledConnectionFactory.class);
    assertThat(jmsTemplate).isNotNull();
    assertThat(pool).isNotNull();
    assertThat(pool).isEqualTo(jmsTemplate.getConnectionFactory());
    ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory();
    assertThat(factory.getBrokerURL()).isEqualTo("tcp://remote-host:10000");
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) Test(org.junit.Test)

Example 3 with PooledConnectionFactory

use of org.apache.activemq.pool.PooledConnectionFactory in project spring-boot by spring-projects.

the class JmsAutoConfigurationTests method testActiveMQOverriddenPoolAndStandalone.

@Test
public void testActiveMQOverriddenPoolAndStandalone() {
    load(TestConfiguration.class, "spring.activemq.pool.enabled:true", "spring.activemq.inMemory:false");
    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    PooledConnectionFactory pool = this.context.getBean(PooledConnectionFactory.class);
    assertThat(jmsTemplate).isNotNull();
    assertThat(pool).isNotNull();
    assertThat(pool).isEqualTo(jmsTemplate.getConnectionFactory());
    ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory();
    assertThat(factory.getBrokerURL()).isEqualTo(ACTIVEMQ_NETWORK_URL);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) Test(org.junit.Test)

Example 4 with PooledConnectionFactory

use of org.apache.activemq.pool.PooledConnectionFactory in project spring-boot by spring-projects.

the class ActiveMQAutoConfigurationTests method customPooledConnectionFactoryConfiguration.

@Test
public void customPooledConnectionFactoryConfiguration() {
    load(EmptyConfiguration.class, "spring.activemq.pool.enabled:true", "spring.activemq.pool.maxConnections:256", "spring.activemq.pool.idleTimeout:512", "spring.activemq.pool.expiryTimeout:4096", "spring.activemq.pool.configuration.maximumActiveSessionPerConnection:1024", "spring.activemq.pool.configuration.timeBetweenExpirationCheckMillis:2048");
    ConnectionFactory connectionFactory = this.context.getBean(ConnectionFactory.class);
    assertThat(connectionFactory).isInstanceOf(PooledConnectionFactory.class);
    PooledConnectionFactory pooledConnectionFactory = (PooledConnectionFactory) connectionFactory;
    assertThat(pooledConnectionFactory.getMaxConnections()).isEqualTo(256);
    assertThat(pooledConnectionFactory.getIdleTimeout()).isEqualTo(512);
    assertThat(pooledConnectionFactory.getMaximumActiveSessionPerConnection()).isEqualTo(1024);
    assertThat(pooledConnectionFactory.getTimeBetweenExpirationCheckMillis()).isEqualTo(2048);
    assertThat(pooledConnectionFactory.getExpiryTimeout()).isEqualTo(4096);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) Test(org.junit.Test)

Example 5 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);
    connectionFactory.setTrustAllPackages(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)

Aggregations

PooledConnectionFactory (org.apache.activemq.pool.PooledConnectionFactory)29 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)18 Test (org.junit.Test)5 Map (java.util.Map)4 ConnectionFactory (javax.jms.ConnectionFactory)4 JmsTemplate (org.springframework.jms.core.JmsTemplate)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)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