use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class QueueToProcessorTransactionTest method testRollbackUsingXmlQueueToProcessor.
@Test
public void testRollbackUsingXmlQueueToProcessor() throws Exception {
// configure routes and add to camel context
context.addRoutes(new SpringRouteBuilder() {
@Override
public void configure() throws Exception {
Policy required = lookup("PROPAGATION_REQUIRED_POLICY", SpringTransactionPolicy.class);
from("activemq:queue:foo").policy(required).process(new ConditionalExceptionProcessor());
}
});
assertResult();
}
use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class QueueToQueueRequestReplyTransactionTest method testRollbackUsingXmlQueueToQueueRequestReplyUsingDynamicMessageSelector.
@Test
public void testRollbackUsingXmlQueueToQueueRequestReplyUsingDynamicMessageSelector() throws Exception {
final ConditionalExceptionProcessor cp = new ConditionalExceptionProcessor(5);
context.addRoutes(new SpringRouteBuilder() {
@Override
public void configure() throws Exception {
Policy required = lookup("PROPAGATION_REQUIRED_POLICY", SpringTransactionPolicy.class);
from("activemq:queue:foo").policy(required).process(cp).to("activemq-1:queue:bar?replyTo=queue:bar.reply");
from("activemq-1:queue:bar").process(new Processor() {
public void process(Exchange e) {
String request = e.getIn().getBody(String.class);
Message out = e.getOut();
String selectorValue = e.getIn().getHeader("camelProvider", String.class);
if (selectorValue != null) {
out.setHeader("camelProvider", selectorValue);
}
out.setBody("Re: " + request);
}
});
}
});
for (int i = 0; i < 5; ++i) {
Object reply = template.requestBody("activemq:queue:foo", "blah" + i);
assertTrue("Received unexpeced reply", reply.equals("Re: blah" + i));
assertTrue(cp.getErrorMessage(), cp.getErrorMessage() == null);
}
}
use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class QueueToQueueTransactionWithoutDefineTransactionManagerTest method testNoTransactionRollbackUsingXmlQueueToQueue.
@Test
public void testNoTransactionRollbackUsingXmlQueueToQueue() throws Exception {
// configure routes and add to camel context
context.addRoutes(new SpringRouteBuilder() {
@Override
public void configure() throws Exception {
errorHandler(noErrorHandler());
from("activemq:queue:foo?transacted=false").process(new ConditionalExceptionProcessor()).to("activemq:queue:bar?transacted=false");
}
});
NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
template.sendBody("activemq:queue:foo", "blah");
notify.matchesMockWaitTime();
assertTrue("Expected only 1 calls to process() (1 failure) but encountered " + getConditionalExceptionProcessor().getCount() + ".", getConditionalExceptionProcessor().getCount() == 1);
}
use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class JpaIdempotentConsumerTest method testFailedExchangesNotAdded.
@SuppressWarnings("unchecked")
@Test
public void testFailedExchangesNotAdded() throws Exception {
context.addRoutes(new SpringRouteBuilder() {
@Override
public void configure() throws Exception {
errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(0).redeliveryDelay(0).logStackTrace(false));
from("direct:start").idempotentConsumer(header("messageId"), jpaMessageIdRepository(lookup(EntityManagerFactory.class), PROCESSOR_NAME)).process(new Processor() {
public void process(Exchange exchange) throws Exception {
String id = exchange.getIn().getHeader("messageId", String.class);
if (id.equals("2")) {
throw new IllegalArgumentException("Damn I cannot handle id 2");
}
}
}).to("mock:result");
}
});
context.start();
// we send in 2 messages with id 2 that fails
getMockEndpoint("mock:error").expectedMessageCount(2);
resultEndpoint.expectedBodiesReceived("one", "three");
sendMessage("1", "one");
sendMessage("2", "two");
sendMessage("1", "one");
sendMessage("2", "two");
sendMessage("1", "one");
sendMessage("3", "three");
assertMockEndpointsSatisfied();
// only message 1 and 3 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(2, ids.size());
assertTrue("Should contain message 1", ids.contains("1"));
assertTrue("Should contain message 3", ids.contains("3"));
}
use of org.apache.camel.spring.SpringRouteBuilder in project camel by apache.
the class TransactionalClientDataSourceLookupTypeTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
// the standard RouteBuilder
return new SpringRouteBuilder() {
public void configure() throws Exception {
// START SNIPPET: e1
// lookup the transaction policy
SpringTransactionPolicy required = lookup(SpringTransactionPolicy.class);
// Notice: transactionErrorHandler is in SpringRouteBuilder
if (useTransactionErrorHandler) {
// useTransactionErrorHandler is only used for unit testing to reuse code
// for doing a 2nd test without this transaction error handler, so ignore
// this. For spring based transaction, end users are encouraged to use the
// transaction error handler instead of the default DeadLetterChannel.
errorHandler(transactionErrorHandler(required));
}
// END SNIPPET: e1
// START SNIPPET: e2
// set the required policy for this route
from("direct:okay").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Elephant in Action")).bean("bookService");
// set the required policy for this route
from("direct:fail").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Donkey in Action")).bean("bookService");
// END SNIPPET: e2
}
};
}
Aggregations