[jboss-user] [JBoss Messaging] - Re: View payload and header data in the table

Pasan Perera do-not-reply at jboss.com
Mon Apr 2 07:27:54 EDT 2012


Pasan Perera [https://community.jboss.org/people/pasanperera] created the discussion

"Re: View payload and header data in the table"

To view the discussion, visit: https://community.jboss.org/message/727718#727718

--------------------------------------------------------------
If you want to get the javax.jms.Message (or any other message types that you have added to the queue) the following will help.

Note that most of the source is copied from JDBCPersistenceManager class in package "jboss-messaging-1.4.2.GA-SP1

Write a query to retrieve all columns from JBM_MSG

    if (rs.next())
    {
      long messageId = rs.getLong("MESSAGE_ID");

      boolean reliable = rs.getString("RELIABLE").equals("Y");

      long expiration = rs.getLong("EXPIRATION");

      long timestamp = rs.getLong("TIMESTAMP");

      byte priority = rs.getByte("PRIORITY");

      byte[] bytes = getBytes(rs, "HEADERS");

      HashMap headers = bytesToMap(bytes);

      byte[] payload = getBytes(rs, "PAYLOAD");

      byte type = rs.getByte("TYPE");

  MapMessage m = (MapMessage)MessageFactory.createMessage(messageId, reliable, expiration, timestamp, priority, headers, payload,
          type);
}

  private boolean usingBinaryStream = true;

  protected byte[] getBytes(ResultSet rs, String column) throws Exception

  {

    if (usingBinaryStream)

    {

      // Get the bytes using a binary stream - likely to be better for large

      // byte[]

      InputStream is = null;

      ByteArrayOutputStream os = null;

      final int BUFFER_SIZE = 4096;

      try

      {

        InputStream i = rs.getBinaryStream(column);

        if (i == null)

        {

          return null;

        }

        is = new BufferedInputStream(rs.getBinaryStream(column), BUFFER_SIZE);

        os = new ByteArrayOutputStream(BUFFER_SIZE);

        int b;

        while ((b = is.read()) != -1)

        {

          os.write(b);

        }

        return os.toByteArray();

      }

      finally

      {

        if (is != null)

        {

          is.close();

        }

        if (os != null)

        {

          os.close();

        }

      }

    }

    else

    {

      // Get the bytes using getBytes() - better for smaller byte[]

      return getVarBinaryColumn(rs, column);

    }

  }

  protected byte[] getVarBinaryColumn(ResultSet rs, String column) throws Exception

  {

    byte[] bytes = rs.getBytes(column);

    if (true)

    {

      // Get rid of the trailing byte

      //  http://jira.jboss.org/jira/browse/JBMESSAGING-825 http://jira.jboss.org/jira/browse/JBMESSAGING-825

      byte[] newBytes = new byte[bytes.length - 1];

      System.arraycopy(bytes, 0, newBytes, 0, bytes.length - 1);

      bytes = newBytes;

    }

    return bytes;

  }

  protected HashMap bytesToMap(byte[] bytes) throws Exception

  {

     if (bytes == null) { return new HashMap(); }

     ByteArrayInputStream bis = new ByteArrayInputStream(bytes);

     DataInputStream dais = new DataInputStream(bis);

     HashMap map = StreamUtils.readMap(dais, true);

     dais.close();

     return map;

  }
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/727718#727718]

Start a new discussion in JBoss Messaging at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2042]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120402/74d1b597/attachment.html 


More information about the jboss-user mailing list