BytesMessage Used to send an array of bytes as a message.
MapMessage Used to send name-value pairs as messages. The names must be
String objects, the values must be either primitive types or Java
ObjectMessage Used to send serializable objects as messages. A serializable object is
an instance of any class that implements java.io.Serializable .
StreamMessage Used to send a stream of Java primitive types as a message.
Used to send a String as a message.
Of the above message types, TextMessage and ObjectMessage are the most fre-
quently used. We will use TextMessage for our example, using other message
types is very similar.
Consult the Java EE JavaDoc for details on the APIs for each of the
message types. Java EE JavaDoc can be found at http://download.
Notice that the createJMSMessageforjmsMyQueue() method is invoked
by the generated sendJMSMessageToMyQueue() , we are expected
to invoke sendJMSMessageToMyQueue() as opposed to invoking
createJMSMessageForjmsMyqueue() directly. In our example, we do this in
the main method of our application.
After adding this invocation, our main() method looks like this:
At this point we have a complete application that will send messages to our message
queue. We can deploy the project and execute it, however, we haven't written any
code to retrieve messages yet, which is the next step we need to take. However,
before moving on, let's go through the generated sendJMSMessageToMyQueue()
method so that we can better understand how it works.
The first thing the method does is to obtain a JMS connection by invoking
the createConnection() method on the injected instance of javax.jms.
ConnectionFactory , and assigning it to a local variable of type javax.jms.