Repository navigation
Expand file tree
/
Copy pathBoot.java
More file actions
65 lines (52 loc) · 2.53 KB
/
Copy pathBoot.java
File metadata and controls
65 lines (52 loc) · 2.53 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
61
62
63
64
65
package com.travelstart.api;
import org.apache.camel.component.netty4.http.DefaultNettySharedHttpServer;
import org.apache.camel.component.netty4.http.NettySharedHttpServerBootstrapConfiguration;
import org.apache.camel.spring.CamelContextFactoryBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan("com.travelstart.api")
public class Boot {
private Logger log = LoggerFactory.getLogger(Boot.class);
public static int PORT = new Integer(System.getProperty("server.port", "8890"));
// bind address
public static String HOST = System.getProperty("server.host", "localhost");
public static int WORKER_COUNT = new Integer(
System.getProperty("server.workers", "" + (Runtime.getRuntime().availableProcessors() * 2)));
public static int MAX_CONTENT_LENGTH = new Integer(System.getProperty("server.max-content-length", "" + (1024 * 1024)));
@Bean("configuration")
public NettySharedHttpServerBootstrapConfiguration nettyConfig() {
NettySharedHttpServerBootstrapConfiguration config =
new NettySharedHttpServerBootstrapConfiguration();
config.setHost(HOST);
config.setPort(PORT);
config.setCompression(true);
config.setWorkerCount(WORKER_COUNT);
config.setChunkedMaxContentLength(MAX_CONTENT_LENGTH);
return config;
}
@Bean(name = "sharedNettyHttpServer", initMethod = "start", destroyMethod = "stop")
public DefaultNettySharedHttpServer server(NettySharedHttpServerBootstrapConfiguration config) {
DefaultNettySharedHttpServer server =
new DefaultNettySharedHttpServer();
server.setNettyServerBootstrapConfiguration(config);
return server;
}
@Bean
CamelContextFactoryBean camelContextFactory() {
final CamelContextFactoryBean context = new CamelContextFactoryBean();
context.setId("camel");
context.setMessageHistory(Boolean.FALSE.toString());
context.setStreamCache(Boolean.TRUE.toString());
return context;
}
public static void main(String[] args) throws InterruptedException {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Boot.class);
context.registerShutdownHook();
context.start();
}
}