Personal notes on Java
For other technologies like HTML, CSS, .NET, PHP, etc. check my other blog

Some usefull java classes/interfaces when using Message-Driven Beans (javax.jms):

Message (interface): is the root interface of all JMS messages. It defines the message header and the acknowledge method used for all messages.

ObjectMessage (interface): An ObjectMessage object is used to send a message that contains a serializable object in the Java programming language ("Java object"). It inherits from the Message interface and adds a body containing a single reference to an object. Only Serializable Java objects can be used.
If a collection of Java objects must be sent, one of the Collection classes provided since JDK 1.2 can be used.
It only defines 2 methods:
  • getObject() Gets the serializable object containing this message's data.
  • setObject(java.io.Serializable object) Sets the serializable object containing this message's data.

Some code examples:

Using Message and ObjectMessage:

    public void onMessage(Message message) {
        ObjectMessage msg = null;
        try {
            if (message instanceof ObjectMessage) {
                msg = (ObjectMessage) message;
                MyEntity e = (MyEntity) msg.getObject();
                persist(e);
            }
        } catch (JMSException ex) {
            e.printStackTrace();
            mdc.setRollbackOnly();
        } catch (Throwable te) {
            te.printStackTrace();
        }
    }

Sem comentários:

Enviar um comentário