use of org.apache.activemq.ActiveMQConnectionFactory in project camel by apache.
the class CamelJmsToFileExample method main.
public static void main(String[] args) throws Exception {
// START SNIPPET: e1
CamelContext context = new DefaultCamelContext();
// END SNIPPET: e1
// Set up the ActiveMQ JMS Components
// START SNIPPET: e2
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
// Note we can explicit name the component
context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
// END SNIPPET: e2
// Add some configuration by hand ...
// START SNIPPET: e3
context.addRoutes(new RouteBuilder() {
public void configure() {
from("test-jms:queue:test.queue").to("file://test");
}
});
// END SNIPPET: e3
// Camel template - a handy class for kicking off exchanges
// START SNIPPET: e4
ProducerTemplate template = context.createProducerTemplate();
// END SNIPPET: e4
// Now everything is set up - lets start the context
context.start();
// START SNIPPET: e5
for (int i = 0; i < 10; i++) {
template.sendBody("test-jms:queue:test.queue", "Test Message: " + i);
}
// END SNIPPET: e5
// wait a bit and then stop
Thread.sleep(1000);
context.stop();
}
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);
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;
}
use of org.apache.activemq.ActiveMQConnectionFactory in project camel by apache.
the class SjmsEndpointTest 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(3);
component.setConnectionFactory(connectionFactory);
camelContext.addComponent("sjms", component);
return camelContext;
}
use of org.apache.activemq.ActiveMQConnectionFactory in project camel by apache.
the class SjmsBatchConsumerTest method createCamelContext.
@Override
public CamelContext createCamelContext() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
registry.put("testStrategy", new ListAggregationStrategy());
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(broker.getTcpConnectorUri());
SjmsComponent sjmsComponent = new SjmsComponent();
sjmsComponent.setConnectionFactory(connectionFactory);
SjmsBatchComponent sjmsBatchComponent = new SjmsBatchComponent();
sjmsBatchComponent.setConnectionFactory(connectionFactory);
CamelContext context = new DefaultCamelContext(registry);
context.addComponent("sjms", sjmsComponent);
context.addComponent("sjms-batch", sjmsBatchComponent);
return context;
}
use of org.apache.activemq.ActiveMQConnectionFactory in project camel by apache.
the class SjmsDestinationCreationStrategyTest method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = new DefaultCamelContext();
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUri);
SjmsComponent component = new SjmsComponent();
component.setConnectionFactory(connectionFactory);
component.setDestinationCreationStrategy(new TestDestinationCreationStrategyTest());
camelContext.addComponent("sjms", component);
return camelContext;
}
Aggregations