In Config.groovy:
rabbitmq {
connectionfactory {
...
}
concurrentConsumers = 5
queues = {
exchange name: 'privategram.email', type: fanout, durable: true
exchange name: 'privategram.error', type: fanout, durable: true
exchange name: 'privategram.comment.created', type: fanout, durable: true
}
retryPolicy.maxAttempts = 3 //bug workaround -- see http://jira.grails.org/browse/GPRABBITMQ-34
}
As you can see, I am using an exchange with a fanout (for now).
In my BaseController.groovy:
def exception = { message ->
log.error(message)
rabbitSend('privategram.error', message)
}
In my ReceiverService:
class ErrorReceieverService {
static rabbitSubscribe = 'privategram.error'
void handleMessage(message) {
log.error "subscribed message received."
}
}
With the following set up, I was never able to send any messages. I was able to receive messages after I sent them using the RabbitMQ management console, so I knew it was something wrong with the rabbitSend method. Upon looking at the documentation, I realized that the method signature was actually wrong! Using 2 parameters means it will be sent to a queue, while using 3 parameter means it will be sent to the exchange. I personally think this api method is flawed because it is not explicit in where it is directing the messages to. But anyways this is how I fixed it:
In my BaseController.groovy:
def exception = { message ->
log.error(message)
rabbitSend('privategram.error', '', message) //notice the additional param.
}
def exception = { message ->
log.error(message)
rabbitSend('privategram.error', '', message) //notice the additional param.
}
Hi Chan,
ReplyDeleteI am working with rabbitmq plugin in Grails and created a grails-app using intellij Idea. I have successfully installed rabbitmq Plugin and when I run my app I can see on Rabbitmq Web management console that my app has created a new connection and also an exchange on rabbitmq server. but when I call rabbitSend in my service or controller I can see the error that symbol rabbitSend can't resolve and also when I run that service following error appears:
groovy.lang.MissingMethodException: No signature of method: static Messages.PopulateService.rabbitSend() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [my.topic, , Hi]
Possible solutions: rabbitSend([Ljava.lang.Object;)
Please guide me how can I resolve this issue.
Regards,
Husnain Taseer
Did you figure this out?
Delete