Created
March 8, 2017 07:39
-
-
Save javierarilos/de4881c8cad72aa221774db10bbd9fae to your computer and use it in GitHub Desktop.
Groovying Camel: Proof of concept for dynamically starting Apache Camel routes from Groovy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Proof of concept of starting Apache Camel routes. | |
Grabs all dependencies, starts Camel and adds two routes to it. | |
- Timer to console | |
- Websockets => RabbitMQ | |
Usage: | |
>>> groovy groovying_camel.groovy | |
End with CTRL+C | |
*/ | |
@Grab('org.apache.camel:camel-core:2.13.1') | |
@Grab(group='org.apache.camel', module='camel-websocket', version='2.13.1') | |
@Grab(group='org.apache.camel', module='camel-rabbitmq', version='2.13.1') | |
@Grab('org.slf4j:slf4j-simple') | |
import org.apache.camel.* | |
import org.apache.camel.impl.* | |
import org.apache.camel.builder.* | |
def camelContext = new DefaultCamelContext() | |
camelContext.addRoutes(new RouteBuilder() { | |
def void configure() { | |
from("timer://jdkTimer?period=10000") | |
.to("log://camelLogger?level=INFO") | |
.process(new Processor() { | |
def void process(Exchange exchange) { | |
println("Hello World!") | |
}}) | |
from("websocket://127.0.0.1:4242/in") | |
.log('>>> received ${body}') | |
.transform().simple('yayyyyy: ${body}') | |
.to("rabbitmq://127.0.0.1/my_important_exchange?routingKey=one_routing_key&username=guest&password=guest") | |
}}) | |
camelContext.start() | |
while(true) | |
sleep(200) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment