-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathBootstrap.java
More file actions
60 lines (48 loc) · 1.54 KB
/
Bootstrap.java
File metadata and controls
60 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package org.javaee7.extra.camel;
import java.util.logging.Level;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.cdi.CdiCamelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Arun Gupta / Markus Eisele
*/
@Singleton
@Startup
public class Bootstrap {
@Inject
CdiCamelContext context;
Logger logger = LoggerFactory.getLogger(Bootstrap.class);
@PostConstruct
public void init() {
logger.info(">> Create CamelContext and register Camel Route.");
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("timer://timer1?period=1000")
.setBody()
.simple("Camel")
.beanRef("helloCamel", "sayHello")
.log(">> Response : ${body}");
}
});
} catch (Exception ex) {
java.util.logging.Logger.getLogger(Bootstrap.class.getName()).log(Level.SEVERE, null, ex);
}
// Start Camel Context
context.start();
logger.info(">> CamelContext created and camel route started.");
}
@PreDestroy
public void shutdown() {
// Graceful Shutdown Camel Context
context.stop();
logger.info(">> CamelContext stopped .");
}
}