Search code examples
grailsrabbitmqgrails-plugingrails-plugin-rabbitmq

When using the Grails RabbitMQ plugin, how do you set message headers/properties when sending messages?


When consuming messages using the plugin, you can access the raw Message and its headers/properties.

When sending messages using the rabbitSend method, it appears from the documentation (http://grails-plugins.github.com/grails-rabbitmq/docs/manual/ref/All%20Classes/rabbitSend.html) that you can only set the exchange name, routing key and message body.

How can these headers/properties be set when sending a message using the rabbitSend method?


Solution

  • At present, it looks like you need to use the underlying rabbitTemplate.convertAndSend() method. The link to the RabbitTemplate Javadoc in the plugin's documentation is broken at the moment, it should point to http://static.springsource.org/spring-amqp/api/org/springframework/amqp/rabbit/core/RabbitTemplate.html

    I found an example of setting the message properties using the rabbitTemplate.convertAndSend() method on the Grails JIRA http://jira.grails.org/browse/GPRABBITMQ-7

    rabbitTemplate.convertAndSend "amq.direct", "work", payload, ({ Message msg ->
        msg.messageProperties.replyTo = new Address("work.reply")
        return msg
    } as MessagePostProcessor)