cnavta edited this page Sep 13, 2010 · 8 revisions


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

This will create a route in your ‘grails-app/routes’ directory:

class MyMessageRoute {
	def configure = {

In the configure closure you have full access to the Camel Java DSL to configure your message routes.

Route Configuration

Simple Example

To create a route from an in-memory queue called “my.queue” to stdout, use:


This would print out any Object sent to “seda:my.queue” to the console.

Slightly More Complex Example

Suppose you wanted to send messages asynchronously to the following Grails Service:

class MyService {
	def myMethod(fooBarText) { “Got text: ${ fooBarText }”

Using Camel’s bean integration, we can deliver messages directly to any Grails Service:

from(“seda:my.queue”).filter {“FooBar”)

This would deliver any message with the text “FooBar” in the body to the myMethod method of the myService service.

This example also illustrates one of the routing enhancements the plug-in offers. You can pass a Closure to the “filter”, “when” and “process” DSL methods.

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”]

This would send the Map “myMessage” to an in-memory queue called “my.queue”.

Camel Components

Apache Camel has a wide variety of built-in Components for message delivery, such as JMS, SMTP, Web Services and Jabber. Take a look at the Apache Camel documentation for a comprehensive list.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.