12.07.2015 Views

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 13 ■ SENDING MESSAGESA session is single-threaded and is used to create messages, producers, and consumers. Like all theobjects you’ve seen so far, sessions come in two different flavors: QueueSession and TopicSession. Themore generic Session allows you to use either one <strong>with</strong> a unified interface.MessagesTo communicate, clients exchange messages; one producer will send a message to a destination, and aconsumer will receive it. Messages are objects that encapsulate information and are divided in threeparts (see Figure 13-8):• A header contains standard information for identifying and routing the message.• Properties are name-value pairs that the application can set or read. Propertiesalso allow destinations to filter messages based on property values.• A body contains the actual message and can take several formats (text, bytes,object, etc.).Figure 13-8. Structure of a JMS messageHeaderThe header has predefined name-value pairs, common to all messages that both clients and providersuse to identify and route messages. They can be seen as message metadata as they give informationabout the message. Each field has associated getter and setter methods defined in the javax.jms.Messageinterface. Some header fields are intended to be set by a client, but many are set automatically by thesend() or the publish() method.Table 13-3 describes each JMS message header field.390

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!