jbrisbin edited this page Sep 14, 2010 · 6 revisions
Clone this wiki locally

The Groovy DSL (Domain Specific Language) for RabbitMQ allows you to mix standard Groovy code with a builder-style syntax for working with a RabbitMQ server. For example, consider the following:

mq.exchange(name: "test", durable: false, autoDelete: true) {
  // Named, non-durable queue
  queue name: "test", routingKey: "test.key", {
    consume tag: "test", onmessage: {msg ->

This example uses the RabbitMQ DSL to:

1. Declare a non-durable, autodelete exchange named “test”
2. Declare a named, non-durable, autodelete queue named “test” and bind that queue to the enclosing exchange.
3. Create a queueing consumer (tagged with “test”) that executes the “onmessage” closure every time a message is received.


The Groovy DSL is intended to be used to create compact, self-documenting, RabbitMQ code similar to what ActiveMQ users have with Camel. Nesting queues within exchanges ensures that an exchange exists and that all queues are properly bound before your
Groovy code is actually run.

If you want to run arbitrary Groovy code and access the RabbitMQ Channel object directly, declare a closure like so:

mq {channel ->
  // Do channel-specific stuff here...

Event System

There is a basic event system in the RabbitMQ DSL, described more in detail on the Events page.


  • Returning a non-null or “true” result from the closure specified on the “onmessage” property causes the consumer to keep listening for messages until the closure returns a false or value.


The RabbitMQ DSL is licensed under the Apache 2 license (included).