Camel
Event bus module using Camel
Usage
1) Add the dependency:
Maven
Gradle
<dependency>
<groupId>io.jooby</groupId>
<artifactId>jooby-camel</artifactId>
<version>4.0.16</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}");
}
}
-
Install Camel
-
Get ProducerTemplate
-
Send message to
direct:foo
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}}");
}
}
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}");
}
}
-
Install Camel.
MyRouteswill be provisioning by Guice. -
Install Guice
-
Also
FooServicewill be provisioning by Guice
|
Important
|
Keep in mind Camel beans are singleton by default, regardless of what dependency injection framework you choose. |
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