Apache Camel Plugin
Dependency :
compile ":camel:0.2"
Summary
Installation
grails install-plugin camel
Description
This plugin has been superseded by the Grails Routing Plugin
Overview
The Apache Camel Grails plug-in allows you to send and route messages to a wide variety of destination endpoints directly from your Controllers and Services. It also provides a new Grails artifact, Routes, to configure your routes using know Enterprise Integration Patterns via the Apache Camel Java DSL.Creating Routes
To create a new route, use the ‘grails create-route’ command:grails create-route MyMessage
class MyMessageRoute {
def configure = {
}
}Route Configuration
Simple Example
To create a route from an in-memory queue called “my.queue†to stdout, use:from(“seda:my.queueâ€).to(“stream:outâ€)
Slightly More Complex Example
Suppose you wanted to send messages asynchronously to the following Grails Service:class MyService {
def myMethod(fooBarText) {
log.info “Got text: ${ fooBarText }â€
}
}from(“seda:my.queueâ€).filter {
it.in.body.contains(“FooBarâ€)
}.to(“bean:myService?methodName=myMethodâ€)Sending Messages
The plug-in provides a new method, ‘sendMessage’, to all Controllers and Services for sending messages to endpoints. It accepts a String endpoint and an Object message:def myMessage = [name:â€fooâ€,data:â€barâ€] sendMessage(“seda:my.queueâ€,myMessage)
Using Camel and ActiveMQ for JMS Messaging
Camel is a very easy way to integrate JMS messaging into your application. Just set up the ActiveMQ Component in your grails-app/conf/spring/resources.groovy:beans = {
activemq(org.apache.activemq.camel.component.ActiveMQComponent) {
brokerURL = 'vm://MyBroker'
}
}sendMessage("activemq:my.queue","Message")
sendMessage("activemq:topic:my.topic","Message")