1 Reply Latest reply on Nov 12, 2015 10:06 AM by Matthew Karlsen

    Modify message body in HornetQ transformer?

    Matthew Karlsen Newbie

      Hello,

       

      Modifying message properties in a transformer is fairly straight forward, and an example transformer is supplied.

       

      However, I would like to modify a message body but am unsure how to get/set text from/for a org.hornetq.core.server.ServerMessage ...

       

      Based on my current searches/reading of documentation the most promising approach seems to be SimpleString messageContents = message.getBodyBuffer().readNullableSimpleString(); (and the reverse).


      However, when I do messageContents.toString(), I just get back

      ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

      ???????????????????????????????????????????????????????????????????????????????????????????????????????????????

       

      Does anyone have any suggestions as to how I can proceed or know of useful documentation for this issue?

       

      I'm hoping it's something relatively simple. However, I'm pretty puzzled at present.

       

      Thanks & regards,

      Matthew

        • 1. Re: Modify message body in HornetQ transformer?
          Matthew Karlsen Newbie

          OK. I have sort of worked it out, in case it is useful for others.

           

          I used Qpid Proton to set the message body, so the body is a string in an AmqpValue object -- it is that object that I got back when I called readNullableSimpleString();

           

          The following code retrieves the bytes and presents them in a readable format:

           

          byte[] amqpValue = new byte[message.getBodyBuffer().readableBytes()];

          message.getBodyBuffer().getBytes(0, amqpValue);

           

          String byteString = null;

          try

          {

              byteString = new String(amqpValue, "UTF-8");

          }

          catch (UnsupportedEncodingException e)

          {

              logger.severe(e.getMessage());

          }

           

          logger.info("amqpValue: " + byteString);

           

          So, now it is a simple case of getting/converting the right bytes.

           

          The issue of setting the message body back after modification remains...

           

          Thanks & regards,

          Matthew