[rabbitmq-discuss] New RabbitMQ Groovy DSL
Jon Brisbin
jon.brisbin at npcinternational.com
Thu Apr 1 15:24:57 BST 2010
I've put the RabbitMQ Groovy DSL code up on Github:
http://github.com/jbrisbin/rabbitmq-dsl
I've tried to include enough documentation to get people going with a command-line DSL runner. I'm always interested in feedback, so please don't be shy. :)
Jon Brisbin
Portal Webmaster
NPC International, Inc.
On Mar 31, 2010, at 6:58 PM, Rob Elsner wrote:
> Jon,
>
> I've used Rabbit in some applications, so when you get that up I'd
> like to help contribute. I'm working on my Groovy, so it's a good
> project.
>
> Thanks,
> Rob
>
> On Wed, Mar 31, 2010 at 2:49 PM, Jon Brisbin
> <jon.brisbin at npcinternational.com> wrote:
>> Folks,
>>
>> "I'm fixin' to" (as we say here in the Midwest) upload some recent work I've done on a Groovy-language DSL for RabbitMQ that lets me integrate with our existing Groovy REST/MVC framework. A simple example looks like:
>>
>> mq.on error: {err ->
>> log.error(err.message)
>> }, myevent: {msg ->
>> log.info(msg.bodyAsString)
>> }
>>
>> // Initialization
>> mq {channel ->
>> //channel.queueDelete("test")
>> //channel.exchangeDelete("test")
>> }
>>
>> mq.exchange(name: "test") {
>> // Named, non-durable queue
>> queue name: "test", routingKey: "test.key", {
>> consume tag: "test", onmessage: "myevent"
>> }
>> // Anonymous (server-generated) non-durable queue
>> queue name: null, routingKey: "test2.key", {
>> consume tag: "test2", onmessage: {msg ->
>> log.info(msg.bodyAsString)
>> log.info("myHeaderValue=" + msg.properties.headers["myHeaderValue"])
>> }
>> }
>> // Poke some messages
>> queue routingKey: "test.key", {
>> publish body: "this is a test"
>> }
>> queue routingKey: "test2.key", {
>> publish myHeaderValue: "customHeader", body: {msg, out ->
>> msg.properties.contentType = "text/plain"
>> out.write("test are test bytes".bytes)
>> }
>> }
>> }
>>
>>
>> To test it, I've got a command-line utility that takes RabbitMQ connection parameters and a Groovy DSL file to operate on (it also handles stdin/stdout for piping).
>>
>> Basics of the system include:
>>
>> * Direct access to the channel when you need custom stuff.
>> * A very basic event system for dispatch error and custom application events.
>> * Using Groovy, I can get a lot of stuff done quickly (works great for utilities, etc...).
>> * On a "consume" closure, if you return a non-null/true result, it will keep listening for more messages (uses a QueuingConsumer).
>> * On a "publish" node, if you specify a closure for the body, it will call() that closure, passing an output stream for you to do custom byte processing, otherwise it'll try and fit whatever you tell it into the message body (strings automagically converted, etc...).
>>
>> There's more to this. This is just a simplistic example. I'll try and document some of that on my github account.
>>
>> I'd be interested in some feedback. I'm wondering what might make this useful to more people than just me. I do make some assumptions about how I'm interacting with RabbitMQ because that's just how we're doing it. I'd be interested in hearing if that doesn't hold for others.
>>
>> I'll post the link when I've got everything put into Git.
>>
>> Jon Brisbin
>> Portal Webmaster
>> NPC International, Inc.
>>
>>
>>
>>
>> _______________________________________________
>> rabbitmq-discuss mailing list
>> rabbitmq-discuss at lists.rabbitmq.com
>> http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>>
More information about the rabbitmq-discuss
mailing list