MessagePayloadProxy doubles memory usage
karypid Sep 8, 2008 10:15 AMHello,
The JBossESB 4.4.GA Programmer's Guide states (page 22, bottom):
By default, all JBossESB 4.2.1GA+ components get and set data on the message through the messages "Default Payload Location".
All ESB components use the MessagePayloadProxy to manage getting and setting of the payload on the message. It handles the default case, as outlined above, but also allows this to be overridden in a uniform manner across all components.
In the immediately following section, it talks about the message factories and body extensions (TextBody, ObjectBody, etc) and says:
It is important to realise that these extensions do not store their data in the default location; data should be retrieved using the corresponding getters on the extension instance.
So, in my message composer, I create my message as follows:
public void setConfiguration(ConfigTree config) throws ConfigurationException { super.setConfiguration(config); mpp = new MessagePayloadProxy(config); mf = XMLMessageFactory.getInstance(); } public Message compose(File f) throws MessageDeliverException { String text = "Hello, ESB!"; // actually, this come from the file... Message m = mf.createTextMessage(text); mpp.setPayload(m, text); }
The above creates two separate strings (with the same content) which is a problem in my case (my messages are rather large strings and memory consumption is significant). To that end, I stopped using the message payload proxy. But then the standard JBossESB actions stop working. I therefore did the following instead:
public void setConfiguration(ConfigTree config) throws ConfigurationException { super.setConfiguration(config); mf = XMLMessageFactory.getInstance(); } public Message compose(File f) throws MessageDeliverException { String text = "Hello, ESB!"; // actually, this come from the file... Message m = mf.createTextMessage(text); m.getBody().add(Body.DEFAULT_LOCATION, text); }
Is this ok? Does MessagePayloadProxy do anything else in addition to setting this entry? Is it "non-API" to work like this (i.e. future ESB versions may break my code)?
In any case, I don't get the logic of this. I noticed that each body type has a default location (Body.DEFAULT_LOCATION, TextBody.DEFAULT_LOCATION, etc). Why is that? Can someone provide an example of a use case?