|
| 1 | +# jooby-camel |
| 2 | + |
| 3 | +[Apache Camel](http://camel.apache.org) integration for Jooby. |
| 4 | + |
| 5 | +Exposes a [CamelContext], [ProducerTemplate] and [ConsumerTemplate]. |
| 6 | + |
| 7 | +NOTE: This module was designed to provide a better integration with Jooby. This module doesn't |
| 8 | +depend on [camel-guice](http://camel.apache.org/guice.html), but it provides similar features. |
| 9 | + |
| 10 | +## dependency |
| 11 | + |
| 12 | +```xml |
| 13 | +<dependency> |
| 14 | + <groupId>org.jooby</groupId> |
| 15 | + <artifactId>jooby-camel</artifactId> |
| 16 | + <version>0.4.2.1</version> |
| 17 | +</dependency> |
| 18 | +``` |
| 19 | + |
| 20 | +## usage |
| 21 | + |
| 22 | +```java |
| 23 | +{ |
| 24 | + use(new Camel() |
| 25 | + .routes((rb, config) -> { |
| 26 | + rb.from("direct:noop").to("mock:out"); |
| 27 | + }) |
| 28 | + ); |
| 29 | + |
| 30 | + get("/noop", req -> { |
| 31 | + req.require(ProducerTemplate.class).sendBody("direct:noop", "NOOP"); |
| 32 | + return "/noop"; |
| 33 | + }); |
| 34 | + |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +Previous example, add a direct route using the Java DSL. A route builder can be created and |
| 39 | +injected by Guice, see next section. |
| 40 | + |
| 41 | +## camel routes |
| 42 | + |
| 43 | +```java |
| 44 | +public class MyRoutes extends RouteBuilder { |
| 45 | + |
| 46 | + @Inject |
| 47 | + public MyRoutes(Service service) { |
| 48 | + this.service = service; |
| 49 | + } |
| 50 | + |
| 51 | + public void configure() { |
| 52 | + from("direct:noop").to("mock:out").bean(service); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +... |
| 57 | +{ |
| 58 | + use(new Camel().routes(MyRoutes.class)); |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +or without extending RouteBuilder: |
| 63 | + |
| 64 | +```java |
| 65 | +public class MyRoutes { |
| 66 | + |
| 67 | + @Inject |
| 68 | + public MyRoutes(RouteBuilder router, Service service) { |
| 69 | + router.from("direct:noop").to("mock:out").bean(service); |
| 70 | + } |
| 71 | + |
| 72 | +} |
| 73 | + |
| 74 | +... |
| 75 | +{ |
| 76 | + use(new Camel().routes(MyRoutes.class)); |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## configuration |
| 81 | + |
| 82 | +Custom configuration is achieved in two ways: |
| 83 | + |
| 84 | +### application.conf |
| 85 | + |
| 86 | +A [CamelContext] can be configured from your ```application.conf```: |
| 87 | + |
| 88 | +```properties |
| 89 | +camel.handleFault = false |
| 90 | +camel.shutdownRoute = Default |
| 91 | +camel.shutdownRunningTask = CompleteCurrentTaskOnly |
| 92 | +camel.streamCaching.enabled = false |
| 93 | +camel.tracing = false |
| 94 | +camel.autoStartup = true |
| 95 | +camel.allowUseOriginalMessage = false |
| 96 | +camel.jmx = false |
| 97 | +``` |
| 98 | + |
| 99 | +Same for [ShutdownStrategy]: |
| 100 | + |
| 101 | +```properties |
| 102 | +camel.shutdown.shutdownRoutesInReverseOrder = true |
| 103 | +camel.shutdown.timeUnit = SECONDS |
| 104 | +camel.shutdown.timeout = 10 |
| 105 | +``` |
| 106 | + |
| 107 | +[ThreadPoolProfile]: |
| 108 | + |
| 109 | +```properties |
| 110 | +camel.threads.poolSize = ${runtime.processors-plus1} |
| 111 | +camel.threads.maxPoolSize = ${runtime.processors-x2} |
| 112 | +camel.threads.keepAliveTime = 60 |
| 113 | +camel.threads.timeUnit = SECONDS |
| 114 | +camel.threads.rejectedPolicy = CallerRuns |
| 115 | +camel.threads.maxQueueSize = 1000 |
| 116 | +camel.threads.id = default |
| 117 | +camel.threads.defaultProfile = true |
| 118 | +``` |
| 119 | + |
| 120 | +and [StreamCachingStrategy]: |
| 121 | + |
| 122 | +```properties |
| 123 | +camel.streamCaching.enabled = false |
| 124 | +camel.streamCaching.spoolDirectory = ${application.tmpdir}${file.separator}"camel"${file.separator}"#uuid#" |
| 125 | +``` |
| 126 | + |
| 127 | +### programmatically |
| 128 | + |
| 129 | +Using the ```doWith(Configurer)``` method: |
| 130 | + |
| 131 | +```java |
| 132 | +{ |
| 133 | + use(new Camel().doWith((ctx, config) -> { |
| 134 | + // set/override any other property. |
| 135 | + })); |
| 136 | +} |
| 137 | +``` |
| 138 | + |
| 139 | +That's all folks! Enjoy it!!! |
| 140 | + |
| 141 | +## appendix: camel.conf |
| 142 | +```properties |
| 143 | +# Camel defaults |
| 144 | +camel.handleFault = false |
| 145 | + |
| 146 | +camel.shutdownRoute = Default |
| 147 | + |
| 148 | +camel.shutdownRunningTask = CompleteCurrentTaskOnly |
| 149 | + |
| 150 | +camel.tracing = false |
| 151 | + |
| 152 | +camel.autoStartup = true |
| 153 | + |
| 154 | +camel.allowUseOriginalMessage = false |
| 155 | + |
| 156 | +camel.jmx = false |
| 157 | + |
| 158 | +# shutdown |
| 159 | +camel.shutdown.shutdownRoutesInReverseOrder = true |
| 160 | +camel.shutdown.timeUnit = SECONDS |
| 161 | +camel.shutdown.timeout = 10 |
| 162 | + |
| 163 | +# thread pool |
| 164 | +camel.threads.poolSize = ${runtime.processors-plus1} |
| 165 | +camel.threads.maxPoolSize = ${runtime.processors-x2} |
| 166 | +camel.threads.keepAliveTime = 60 |
| 167 | +camel.threads.timeUnit = SECONDS |
| 168 | +camel.threads.rejectedPolicy = CallerRuns |
| 169 | +camel.threads.maxQueueSize = 1000 |
| 170 | +camel.threads.id = default |
| 171 | +camel.threads.defaultProfile = true |
| 172 | + |
| 173 | +# stream caching |
| 174 | +camel.streamCaching.enabled = false |
| 175 | +camel.streamCaching.spoolDirectory = ${application.tmpdir}${file.separator}"camel"${file.separator}"#uuid#" |
| 176 | + |
| 177 | +``` |
| 178 | + |
0 commit comments