1 Reply Latest reply on Sep 10, 2008 9:01 PM by tfennelly

    MessagePayloadProxy doubles memory usage

      Hello,

      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?


        • 1. Re: MessagePayloadProxy doubles memory usage
          tfennelly

          I'm not sure how you're getting 2 Strings, but the payload proxy is not creating it. How about simplifying this a little and just using a standard message.

          So just try:

          Message msg = MessageFactory.getInstance().getMessage();
          mpp.setPayload(msg, text);
          ....
          text = (String) mpp.getPayload(msg);


          If your messages are large (of course that depends on what you mean by large), you should really be considering splitting the message. See the "huge-spli-enrich...." quickstart. Sucking them into Strings in memory will kill your system!