XmlSlurper
in Groovy scripts to process XML messages. There are aspects that need to be considered regarding memory consumption. Consider the following code snippet:def body = message.getBody(java.lang.String)
def xml = new XmlSlurper().parseText(body)
body
variable is just used to provide input to the XmlSlurper
. This is fine as long as the body is of type java.lang.String
. In all other cases conversion to java.lang.String
will be applied, which requires allocation of additional memory for the String
object. Note that when the message body is large, or when many messages are processed in parallel, the additional memory footprint might even cause a java.lang.OutOfMemoryError
. Ultimately the OutOfMemoryError
would interrupt the message processing.XmlSlurper
would accept the body as it is, or if the body could be streamed. Then, a better approach is to stream the message body to the XmlSlurper
by using message.getBody(java.io.Reader)
, as shown in the following snippet:def body = message.getBody(java.io.Reader)
def xml = new XmlSlurper().parse(body)
body
variable is now a java.io.Reader
that is just a reference to the message payload object, thus reducing memory consumption and contributing to reliability of your integration scenario.You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
10 | |
9 | |
9 | |
8 | |
8 | |
6 | |
5 | |
5 | |
5 |