Search in sources :

Example 51 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project camel by apache.

the class TransactedAsyncExceptionTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(BROKER_URI);
    connectionFactory.getRedeliveryPolicy().setInitialRedeliveryDelay(0);
    connectionFactory.getRedeliveryPolicy().setRedeliveryDelay(0);
    connectionFactory.getRedeliveryPolicy().setUseCollisionAvoidance(false);
    connectionFactory.getRedeliveryPolicy().setUseExponentialBackOff(false);
    connectionFactory.getRedeliveryPolicy().setMaximumRedeliveries(TRANSACTION_REDELIVERY_COUNT);
    SjmsComponent component = new SjmsComponent();
    component.setConnectionFactory(connectionFactory);
    camelContext.addComponent("sjms", component);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) SjmsComponent(org.apache.camel.component.sjms.SjmsComponent)

Example 52 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project camel by apache.

the class SjmsEndpointNameOverrideTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://broker?broker.persistent=false&broker.useJmx=false");
    SjmsComponent component = new SjmsComponent();
    component.setConnectionCount(1);
    component.setConnectionFactory(connectionFactory);
    camelContext.addComponent(BEAN_NAME, component);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory)

Example 53 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory in project camel by apache.

the class JmsEndpointConfigurationTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry jndi = super.createRegistry();
    jndi.bind("myConnectionFactory", new ActiveMQConnectionFactory("vm:myBroker"));
    return jndi;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory)

Example 54 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory 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 55 with ActiveMQConnectionFactory

use of org.apache.activemq.ActiveMQConnectionFactory 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

ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)69 CamelContext (org.apache.camel.CamelContext)25 SjmsComponent (org.apache.camel.component.sjms.SjmsComponent)16 ConnectionFactory (javax.jms.ConnectionFactory)11 Test (org.junit.Test)10 PooledConnectionFactory (org.apache.activemq.pool.PooledConnectionFactory)9 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)8 JmsTemplate (org.springframework.jms.core.JmsTemplate)7 Connection (javax.jms.Connection)6 Session (javax.jms.Session)6 Before (org.junit.Before)5 MessageProducer (javax.jms.MessageProducer)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)4 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)4 File (java.io.File)3 Destination (javax.jms.Destination)3 JMSException (javax.jms.JMSException)3 MessageConsumer (javax.jms.MessageConsumer)3 BrokerService (org.apache.activemq.broker.BrokerService)3 ArrayList (java.util.ArrayList)2