Which JMS Message should I use ?

Discussions

General J2EE: Which JMS Message should I use ?

  1. Which JMS Message should I use ? (3 messages)

    Hi All,
        I have to send to a queue a byte[] , which message object should I use , BytesMessage or StreamMessage ?.

    Thanks
  2. If the array is small, ByteMessage. If the array is very large (1 M or so), use a StreamMessage.
  3. Depends on what you want to do.

    The main difference between a BytesMessage and a StreamMessage is
    that a BytesMessage is unstructured,unformatted, and untyped
    and a StreamMessage has type information.

    Let's say I am producing a bunch of scientific data as datatype float.
    If I use a StreamMessage.writeFloat() both the value and the datatype
    gets recorded in the Message. So if the comsumer of the StreamMessage
    tries a readBoolean() a JMSException will get thrown.

    If I used a BytesMessage.writeFloat() the only thing that gets recorded
    is the bytes representation of the float. The consumer can call
    readBoolean() and get each member of the byte array as a boolean.
    Propably not what you want to happen.

    BytesMessage is good for when I want to do a file upload via JMS.
    Convert the image,Word doc,etc. as a byte[], send it as a BytesMessage,
    then have the JMS consumer get the byte[] payload and put it in an Oracle
    BLOB or something.

    Jirawat Uttayaya
  4. Ugh. Listen to what Jirawat said. I got Byte/StreamMessages mixed up with Blobs in JDBC, and what I said was complete gibberish.