Closed rblazquez closed 9 years ago
Sorry im not familiarized with JmsTemplate ... i see that probably the plugin way is closer to the spring way. I see related documentation fragment;
" To accommodate the setting of a message’s properties, headers, and body that can not be generically encapsulated inside a converter class, the MessagePostProcessor interface gives you access to the message after it has been converted, but before it is sent. The example below demonstrates how to modify a message header and a property after a java.util.Map is converted to a message.
public void sendWithConversion() { Map map = new HashMap(); map.put("Name", "Mark"); map.put("Age", new Integer(47)); jmsTemplate.convertAndSend("testQueue", map, new MessagePostProcessor() { public Message postProcessMessage(Message message) throws JMSException { message.setIntProperty("AccountID", 1234); message.setJMSCorrelationID("123-00001"); return message; } }); }
"
But im still missing how to fit the pieces
From what i see in the code:
def send(destination, message, String jmsTemplateBeanName = null, Closure callback = null) {
if (disabled) {
log.warn "not sending message [$message] to [$destination] because JMS is disabled in config"
return
}
def ctx = normalizeServiceCtx(destination, jmsTemplateBeanName)
logAction "Sending JMS message '$message' to ", ctx
ctx.with {
if (callback) {
jmsTemplate.convertAndSend(ndestination, message, toMessagePostProcessor(jmsTemplate, callback))
}
else {
jmsTemplate.convertAndSend(ndestination, message)
}
}
}
protected MessagePostProcessor toMessagePostProcessor(JmsTemplate template, Closure callback) {
new GrailsMessagePostProcessor(jmsService: this, jmsTemplate: template, processor: callback)
}
convertAndSend method is hided and not accesible so there is no way to set a MessagePostProcessor where to setup the property this way.
Would it be possible to define and use a custom JmsTemplate to solve this problem?
I seen docs for 2.0.0M1
"Message post processors can either augment the passed Message object, or create a new one. Because of this, the post processor must return the message object that is to be sent."
jmsService.send(topic: 'somethingHappened', 1) { Message msg ->
msg.JMSCorrelationID = "correlate"
msg
}
Would this works for 1.3 also?
Yes @rblazquez, has been available for a while (since 2011). See JmsService.groovy.
Hello,
Are JMS properties supported by the plugin?
In the Java way it would be done working with the "Message" object it self ... how would be the prefered way to get/set JMS properties in grails?
Thanks.