groovy - How to send and receive domain objects with rabbitMQ plugin and grails -
i've went on excellent documentation rabbitmq plugin. however, still confused few things.
scenario
my application take file upload user, various things file , accordingly set properties on domain object. of work can labor intensive using queue. envision requests being queued , consumer picking requests queue , consuming them.
questions
i want store domain object in queue. by: rabbitsend 'myqueue', colorobj
. colorobj
is object of domain class color
however, in colorservice
handlemessage(...)
when fetch item queue, item not of type color
. please note on rabbitmq dashboard can see items being inserted in queue, queue initiation in config.groovy
fine (i using amq.direct
)
- how can send , fetch domain object queue?
- from behavior i've seen far,
handlemessage
not need instantiated. if don't callcolorservice
still executeshandlemessage
itself. normal behavior?
below code:
controller
color colorobj = colorservice.newrequest(params, request.getfile('color.filename') if (colorobj.validate) rabbitsend 'myqueue', colorobj ...
service
class colorservice { static rabbitqueue = 'myqueue' void handlemessage(message) { println "came in message: " + message instanceof color //this prints false } }
as shows in documentation, can either send string
or map
why not send id
of domain object:
rabbitsend 'myqueue', colorobj.id
then, load in when message processed:
void handlemessage(message) { println "got ${color.get( message )}" }
or, if don't need domain object until message processed, send map of required data, , have service create domain object after processed successfully?
Comments
Post a Comment