1. Camel
Event bus module using Camel
1.1. Usage
1) Add the dependency:
Maven
Gradle
<dependency>
<groupId>io.jooby</groupId>
<artifactId>jooby-camel</artifactId>
<version>3.5.3</version>
</dependency>
2) Install
Java
Kotlin
import io.jooby.camel.CamelModule;
{
install(new CamelModule(new MyRoutes())); (1)
get("/{msg}", ctx -> {
ProducerTemplate producer = require(ProducerTemplate.class); (2)
producer.sendBody("direct:foo", ctx.path("msg").value()); (3)
...
});
}
public class MyRoutes extends RouteBuilder {
@Override public void configure() throws Exception {
from("direct://foo")
.log("${body}");
}
}
1 | Install Camel |
2 | Get ProducerTemplate |
3 | Send message to direct:foo |
1.2. Configuration files
Camel module integrates with application.conf
properties files:
application.conf
myprop = "my prop value"
Java
Kotlin
public class MyRoutes extends RouteBuilder {
@Override public void configure() throws Exception {
from("direct://foo")
.log("{{myprop}}");
}
}
1.3. Dependency Injection Support
Camel module integrates with GuiceModule
or SpringModule
. Here is an example with Guice:
Java
Kotlin
import io.jooby.guice.GuiceModule;
import io.jooby.camel.CamelModule;
{
install(new CamelModule(MyRoutes.class)); (1)
install(new GuiceModule()); (2)
}
public class MyRoutes extends RouteBuilder {
@Override public void configure() throws Exception {
from("direct://foo")
.bean(FooService.class) (3)
.log("${body}");
}
}
1 | Install Camel. MyRoutes will be provisioning by Guice. |
2 | Install Guice |
3 | Also FooService will be provisioning by Guice |
Keep in mind Camel beans are singleton by default, regardless of what dependency injection framework you choose. |
1.4. Auto Configuration
Camel modules can be fully configured from application.conf
file.
application.conf
camel.main.name = My Camel Context
camel.threadpool.poolSize = 10
See Auto Configuration and Camel Main Options