use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class TransactionalClientDataSourceWithOnExceptionRollbackTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new SpringRouteBuilder() {
public void configure() throws Exception {
// use required as transaction policy
SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
// configure to use transaction error handler and pass on the required as it will fetch
// the transaction manager from it that it needs
errorHandler(transactionErrorHandler(required));
// on exception is also supported
onException(IllegalArgumentException.class).handled(false).to("mock:error").rollback();
from("direct:okay").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Elephant in Action")).bean("bookService");
from("direct:fail").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Donkey in Action")).bean("bookService");
}
};
}
use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class TransactionalClientDataSourceWithOnExceptionTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new SpringRouteBuilder() {
public void configure() throws Exception {
// use required as transaction policy
SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
// configure to use transaction error handler and pass on the required as it will fetch
// the transaction manager from it that it needs
errorHandler(transactionErrorHandler(required));
// on exception is also supported
onException(IllegalArgumentException.class).handled(false).to("mock:error");
from("direct:okay").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Elephant in Action")).bean("bookService");
from("direct:fail").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Donkey in Action")).bean("bookService");
}
};
}
use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class JpaRouteEndpointTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() {
return new SpringRouteBuilder() {
public void configure() throws Exception {
JpaEndpoint jpa = new JpaEndpoint();
jpa.setCamelContext(context);
jpa.setEntityType(SendEmail.class);
jpa.setEntityManagerFactory(context.getRegistry().lookupByNameAndType("entityManagerFactory", EntityManagerFactory.class));
from("direct:start").to(jpa).to("mock:result");
}
};
}
use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class JpaIdempotentConsumerTest method testDuplicateMessagesAreFilteredOut.
@SuppressWarnings("unchecked")
@Test
public void testDuplicateMessagesAreFilteredOut() throws Exception {
context.addRoutes(new SpringRouteBuilder() {
@Override
public void configure() throws Exception {
// START SNIPPET: idempotent
from("direct:start").idempotentConsumer(header("messageId"), jpaMessageIdRepository(lookup(EntityManagerFactory.class), PROCESSOR_NAME)).to("mock:result");
// END SNIPPET: idempotent
}
});
context.start();
resultEndpoint.expectedBodiesReceived("one", "two", "three");
sendMessage("1", "one");
sendMessage("2", "two");
sendMessage("1", "one");
sendMessage("2", "two");
sendMessage("1", "one");
sendMessage("3", "three");
assertMockEndpointsSatisfied();
// all 3 messages should be in jpa repo
Set<String> ids = new HashSet<String>();
Query query = entityManager.createQuery(SELECT_ALL_STRING);
query.setParameter(1, PROCESSOR_NAME);
List<MessageProcessed> list = query.getResultList();
for (MessageProcessed item : list) {
ids.add(item.getMessageId());
}
assertEquals(3, ids.size());
assertTrue("Should contain message 1", ids.contains("1"));
assertTrue("Should contain message 2", ids.contains("2"));
assertTrue("Should contain message 3", ids.contains("3"));
}
use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class JpaPollingConsumerLockEntityTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() {
return new SpringRouteBuilder() {
public void configure() {
AggregationStrategy enrichStrategy = new AggregationStrategy() {
@Override
public Exchange aggregate(Exchange originalExchange, Exchange jpaExchange) {
Customer customer = jpaExchange.getIn().getBody(Customer.class);
customer.setOrderCount(customer.getOrderCount() + 1);
return jpaExchange;
}
};
onException(Exception.class).setBody().simple("${exception}").to("mock:error").handled(true);
from("direct:locked").onException(OptimisticLockException.class).redeliveryDelay(60).maximumRedeliveries(2).end().pollEnrich().simple("jpa://" + Customer.class.getName() + "?lockModeType=OPTIMISTIC_FORCE_INCREMENT&query=select c from Customer c where c.name like '${header.name}'").aggregationStrategy(enrichStrategy).to("jpa://" + Customer.class.getName()).setBody().simple("orders: ${body.orderCount}").to("mock:locked");
from("direct:not-locked").pollEnrich().simple("jpa://" + Customer.class.getName() + "?query=select c from Customer c where c.name like '${header.name}'").aggregationStrategy(enrichStrategy).to("jpa://" + Customer.class.getName()).setBody().simple("orders: ${body.orderCount}").to("mock:not-locked");
}
};
}
Aggregations