Skip to content

Instantly share code, notes, and snippets.

@javierarilos
Created May 16, 2014 13:53
Show Gist options
  • Save javierarilos/78a374d5b033ce4735e2 to your computer and use it in GitHub Desktop.
Save javierarilos/78a374d5b033ce4735e2 to your computer and use it in GitHub Desktop.
/*
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