This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.zimek</groupId> | |
<artifactId>myproj</artifactId> | |
<version>1.0-SNAPSHOT</version> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Exchange createExchange(final int redeliveryCount) { | |
final Exchange exchange = ExchangeBuilder.anExchange(context()).build(); | |
exchange.getIn().setHeader(ServiceConstants.REDELIVERY_COUNT_HEADER_NAME, redeliveryCount); | |
return exchange; | |
} | |
@Test | |
public void should_increment_redelivery_count_and_send_to_jms_endpoint() throws Exception { | |
configureMockEndpoint(); | |
final Exchange requestExchange = createExchange(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void configureMockEndpoint() throws Exception { | |
final AdviceWithRouteBuilder mockAdvice = new AdviceWithRouteBuilder() { | |
@Override | |
public void configure() throws Exception { | |
replaceFromWith("direct:deadLetterQueueMock"); | |
interceptSendToEndpoint("jms:*") | |
.skipSendToOriginalEndpoint() | |
.process(exchange -> exchange.getIn().setBody(TEST_BODY_PAYLOAD)); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected AbstractApplicationContext createApplicationContext() { | |
return new AnnotationConfigApplicationContext(ContextConfiguration.class); | |
} | |
@Configuration | |
@EnableAutoConfiguration | |
@ComponentScan(basePackageClasses = {ActivemqConfiguration.class, QueueReaderRoute.class}, | |
useDefaultFilters = false, | |
includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RedeliveryProcessor implements Processor { | |
private static final int MAX_REDELIVERIES = 5; | |
@Override | |
public void process(Exchange exchange) throws Exception { | |
final int redeliveryCount = exchange.getIn().getHeader(ServiceConstants.REDELIVERY_COUNT_HEADER_NAME, Integer.class).intValue(); | |
if (redeliveryCount <= MAX_REDELIVERIES) { | |
exchange.getIn().setHeader(ServiceConstants.REDELIVERY_COUNT_HEADER_NAME, redeliveryCount + 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class QueueReaderRoute extends RouteBuilder { | |
@Override | |
public void configure() throws Exception { | |
from("jms:deadLetterQueue") | |
.routeId(ServiceConstants.QUEUE_READER_ROUTE_ID) | |
.process(new RedeliveryProcessor()) | |
.to(ExchangePattern.InOnly, "jms:destinationQueue") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelloRouteTest extends CamelSpringTestSupport { | |
private static final String TEST_MESSAGE_PAYLOAD = "my message"; | |
@Override | |
protected AbstractApplicationContext createApplicationContext() { | |
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); | |
ctx.scan("com.mzimecki.camel.spring"); | |
ctx.refresh(); | |
return ctx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
@RequestMapping("service") | |
public class HelloService { | |
@Autowired | |
private ProducerTemplate producer; | |
@Autowired | |
private CamelContext camelContext; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class HelloRoute extends RouteBuilder { | |
@Override | |
public void configure() throws Exception { | |
from(ServiceConstants.HELLO_SERVICE_ENDPOINT) | |
.id(ServiceConstants.HELLO_ROUTE_ID) | |
.log("I'm in the Camel Route!") | |
.process(new HelloProcessor()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SpringBootApplication | |
@EnableAutoConfiguration | |
@ComponentScan(value = "com.mzimecki.camel.spring") | |
public class ServiceLauncher { | |
public static void main(String[] args) { | |
SpringApplication.run(ServiceLauncher.class, args); | |
} | |
} |
NewerOlder