Last active
September 18, 2017 13:40
-
-
Save gysel/9fe8a2eeb2f8ab731256d3329fd7d289 to your computer and use it in GitHub Desktop.
Camel onCompletion example
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
package com.example.oncompletiontest; | |
import org.apache.camel.spring.boot.CamelSpringBootApplicationController; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.context.ConfigurableApplicationContext; | |
@SpringBootApplication | |
public class OncompletionTestApplication { | |
public static void main(String[] args) { | |
ConfigurableApplicationContext context = SpringApplication.run(OncompletionTestApplication.class, args); | |
CamelSpringBootApplicationController controller = context.getBean(CamelSpringBootApplicationController.class); | |
controller.run(); | |
} | |
} |
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
package com.example.oncompletiontest; | |
import org.apache.camel.builder.RouteBuilder; | |
import org.apache.camel.model.dataformat.BindyType; | |
import org.springframework.stereotype.Component; | |
@Component | |
public class Route extends RouteBuilder { | |
@Override | |
public void configure() throws Exception { | |
from("file:in").setHeader("message", body()) | |
.onCompletion().bean(TestProcessor.class, "testMethod").end() | |
.choice() | |
.when(header("camelfilenameonly").contains("test1.csv")) | |
.unmarshal().bindy(BindyType.Csv, Test1CsvDto.class) | |
.bean(TestProcessor.class, "processTest1Object").stop() | |
.otherwise() | |
.choice() | |
.when(header("camelfilenameonly").contains("test2.csv")) | |
//Unmarshal csv | |
.unmarshal().bindy(BindyType.Csv, Test2CsvDto.class) | |
.bean(TestProcessor.class, "processTest2") | |
.stop(); | |
} | |
} |
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
package com.example.oncompletiontest; | |
import org.apache.camel.dataformat.bindy.annotation.CsvRecord; | |
@CsvRecord(separator = ",") | |
public class Test1CsvDto { | |
public String message; | |
} |
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
package com.example.oncompletiontest; | |
import org.apache.camel.dataformat.bindy.annotation.CsvRecord; | |
import org.apache.camel.dataformat.bindy.annotation.DataField; | |
@CsvRecord(separator = ",") | |
public class Test2CsvDto { | |
@DataField(pos = 1, position = 1) | |
public String message; | |
} |
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
package com.example.oncompletiontest; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class TestProcessor { | |
private Logger log = LoggerFactory.getLogger(TestProcessor.class); | |
public void testMethod(Object o) { | |
log.info("testmethod"); | |
} | |
public void processTest1Object(Object o) { | |
log.info("processTest1Object"); | |
} | |
public void processTest2(Object o) { | |
log.info("processTest2"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment