javax.jms

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server GlassFish » jms » javax.jms 
javax.jms
atr Architecture

The Java Message Service (JMS) API provides a common way for Java programs to create, send, receive and read an enterprise messaging system's messages.

JMS Applications

A JMS application is composed of the following parts:

  • JMS Provider - a messaging system that implements the JMS API in addition to the other administrative and control functionality required of a full-featured messaging product
  • JMS Clients - the Java language programs that send and receive messages
  • Messages - objects that are used to communicate information between the clients of an application
  • Administered Objects - provider-specific objects that clients look up and use to interact portably with a JMS provider
  • Non-JMS Clients - clients that use a message system's native client API instead of the JMS API. If the application predated the availability of the JMS API, it is likely that it will include both JMS clients and non-JMS clients.

Administration

JMS providers differ significantly in their implementations of underlying messaging technology. There are also major differences in how a JMS provider's system is installed and administered.

For JMS clients to be portable, they must be isolated from these proprietary aspects of a provider. This is done by defining JMS administered objects that are created and customized by a provider's administrator and later used by clients. The client uses them through JMS interfaces that are portable. The administrator creates them using provider-specific facilities.

There are two types of JMS administered objects:

  • ConnectionFactory - the object a client uses to create a connection with a JMS provider
  • Destination - the object a client uses to specify the destination of messages it is sending and the source of messages it receives

Administered objects are placed in a Java Naming and Directory InterfaceTM (JNDI) namespace by an administrator. A JMS client typically notes in its documentation the JMS administered objects it requires and how the JNDI names of these objects should be provided to it.

Two Messaging Styles

The JMS specification defines two styles of messaging: the point-to-point (PTP) or the publish-and-subscribe (Pub/Sub). These styles can be combined in a single application, or a given application can use just one of these styles.

The JMS API defines these two styles because they represent two of the dominant approaches to messaging currently in use. While the domains have many similarities, they also have some differences. JMS provides a unified programming interface to allow the client programmer to easily send and receive message using either domain, but the client programmer must also be aware of the differences between the domains. The key differences relate to how message persistence is handled, and the meaning of certain message attributes.

JMS Interfaces

When programming an application client, the programmer may either program using the domain specific interfaces, or may use the common interfaces. The key interfaces are listed in the table below. The preferred model is to use the common interfaces. The advantage to using the common interfaces is that both point-to-point and pub/sub tasks can be combined in one session, allowing transactions to operate over both domains.

In earlier versions of JMS, there were separate class hierarchies for the pub/sub and point-to-point programming models that had to be used. These class hierarchies are retained to support backward compatibility with earlier versions of the JMS API, but client developers are encouraged to use the common interfaces.

Relationship of PTP and Pub/Sub interfaces
JMS Common PTP Domain Pub/Sub Domain
ConnectionFactory QueueConnectionFactory TopicConnectionFactory
Connection QueueConnection TopicConnection
Destination Queue Topic
Session QueueSession TopicSession
MessageProducer QueueSender TopicPublisher
MessageConsumer QueueReceiver TopicSubscriber

The following provides a brief definition of these JMS concepts. See the PTP and Pub/Sub chapters of the JMS specification for more information.

  • ConnectionFactory - an administered object used by a client to create a Connection
  • Connection - an active connection to a JMS provider
  • Destination - an administered object that encapsulates the identity of a message destination
  • Session - a single-threaded context for sending and receiving messages
  • MessageProducer - an object created by a Session that is used for sending messages to a destination
  • MessageConsumer - an object created by a Session that is used for receiving messages sent to a destination

The term consume is used in this document to mean the receipt of a message by a JMS client; that is, a JMS provider has received a message and has given it to its client. Since the JMS API supports both synchronous and asynchronous receipt of messages, the term consume is used when there is no need to make a distinction between them.

The term produce is used as the most general term for sending a message. It means giving a message to a JMS provider for delivery to a destination.

Developing a JMS Application

Broadly speaking, a JMS application is one or more JMS clients that exchange messages. The application may also involve non-JMS clients; however, these clients use the JMS provider's native API in place of the JMS API.

A JMS application can be architected and deployed as a unit. In many cases, JMS clients are added incrementally to an existing application.

The message definitions used by an application may originate with JMS, or they may have been defined by the non-JMS part of the application.

Developing a JMS Client

A typical JMS client executes the following setup procedure:

  • Use JNDI to find a ConnectionFactory object
  • Use JNDI to find one or more Destination objects
  • Use the ConnectionFactory to create a JMS Connection. At this point, message delivery is inhibited
  • Use the Connection to create one or more JMS Sessions
  • Use a Session and the Destinations to create the MessageProducers and MessageConsumers needed
  • Start message delivery for the Connection. Messages will be delivered to MessageConsumers

At this point a client has the basic setup needed to produce and consume messages.

Package Specification

Java Message Service Specification - Version 1.1

Related Documentation

Java Message Service Tutorial
Java Source File NameTypeComment
BytesMessage.javaInterface A BytesMessage object is used to send a message containing a stream of uninterpreted bytes.
Connection.javaInterface A Connection object is a client's active connection to its JMS provider.
ConnectionConsumer.javaInterface For application servers, Connection objects provide a special facility for creating a ConnectionConsumer (optional).
ConnectionFactory.javaInterface A ConnectionFactory object encapsulates a set of connection configuration parameters that has been defined by an administrator.
ConnectionMetaData.javaInterface A ConnectionMetaData object provides information describing the Connection object.
DeliveryMode.javaInterface The delivery modes supported by the JMS API are PERSISTENT and NON_PERSISTENT.

A client marks a message as persistent if it feels that the application will have problems if the message is lost in transit. A client marks a message as non-persistent if an occasional lost message is tolerable.

Destination.javaInterface A Destination object encapsulates a provider-specific address. The JMS API does not define a standard address syntax.
ExceptionListener.javaInterface If a JMS provider detects a serious problem with a Connection object, it informs the Connection object's ExceptionListener, if one has been registered.
IllegalStateException.javaClass

This exception is thrown when a method is invoked at an illegal or inappropriate time or if the provider is not in an appropriate state for the requested operation.

InvalidClientIDException.javaClass

This exception must be thrown when a client attempts to set a connection's client ID to a value that is rejected by a provider.

InvalidDestinationException.javaClass

This exception must be thrown when a destination either is not understood by a provider or is no longer valid.

InvalidSelectorException.javaClass

This exception must be thrown when a JMS client attempts to give a provider a message selector with invalid syntax.

JMSException.javaClass

This is the root class of all JMS API exceptions.

It provides the following information:

  • A provider-specific string describing the error.
JMSSecurityException.javaClass

This exception must be thrown when a provider rejects a user name/password submitted by a client.

MapMessage.javaInterface A MapMessage object is used to send a set of name-value pairs. The names are String objects, and the values are primitive data types in the Java programming language.
Message.javaInterface The Message interface is the root interface of all JMS messages.
MessageConsumer.javaInterface A client uses a MessageConsumer object to receive messages from a destination.
MessageEOFException.javaClass

This exception must be thrown when an unexpected end of stream has been reached when a StreamMessage or BytesMessage is being read.

MessageFormatException.javaClass

This exception must be thrown when a JMS client attempts to use a data type not supported by a message or attempts to read data in a message as the wrong type.

MessageListener.javaInterface A MessageListener object is used to receive asynchronously delivered messages.

Each session must insure that it passes messages serially to the listener.

MessageNotReadableException.javaClass

This exception must be thrown when a JMS client attempts to read a write-only message.

MessageNotWriteableException.javaClass

This exception must be thrown when a JMS client attempts to write to a read-only message.

MessageProducer.javaInterface A client uses a MessageProducer object to send messages to a destination.
ObjectMessage.javaInterface 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.
Queue.javaInterface A Queue object encapsulates a provider-specific queue name.
QueueBrowser.javaInterface A client uses a QueueBrowser object to look at messages on a queue without removing them.

The getEnumeration method returns a java.util.Enumeration that is used to scan the queue's messages.

QueueConnection.javaInterface A QueueConnection object is an active connection to a point-to-point JMS provider.
QueueConnectionFactory.javaInterface A client uses a QueueConnectionFactory object to create QueueConnection objects with a point-to-point JMS provider.

QueueConnectionFactory can be used to create a QueueConnection, from which specialized queue-related objects can be created.

QueueReceiver.javaInterface A client uses a QueueReceiver object to receive messages that have been delivered to a queue.

Although it is possible to have multiple QueueReceivers for the same queue, the JMS API does not define how messages are distributed between the QueueReceivers.

If a QueueReceiver specifies a message selector, the messages that are not selected remain on the queue.

QueueRequestor.javaClass The QueueRequestor helper class simplifies making service requests.

The QueueRequestor constructor is given a non-transacted QueueSession and a destination Queue.

QueueSender.javaInterface A client uses a QueueSender object to send messages to a queue.

Normally, the Queue is specified when a QueueSender is created.

QueueSession.javaInterface A QueueSession object provides methods for creating QueueReceiver, QueueSender, QueueBrowser, and TemporaryQueue objects.

If there are messages that have been received but not acknowledged when a QueueSession terminates, these messages will be retained and redelivered when a consumer next accesses the queue.

A QueueSession is used for creating Point-to-Point specific objects.

ResourceAllocationException.javaClass

This exception is thrown when a provider is unable to allocate the resources required by a method.

ServerSession.javaInterface A ServerSession object is an application server object that is used by a server to associate a thread with a JMS session (optional).

A ServerSession implements two methods:

  • getSession - returns the ServerSession's JMS session.
  • start - starts the execution of the ServerSession thread and results in the execution of the JMS session's run method.

A ConnectionConsumer implemented by a JMS provider uses a ServerSession to process one or more messages that have arrived.

ServerSessionPool.javaInterface A ServerSessionPool object is an object implemented by an application server to provide a pool of ServerSession objects for processing the messages of a ConnectionConsumer (optional).

Its only method is getServerSession.

Session.javaInterface

A Session object is a single-threaded context for producing and consuming messages.

StreamMessage.javaInterface A StreamMessage object is used to send a stream of primitive types in the Java programming language.
TemporaryQueue.javaInterface A TemporaryQueue object is a unique Queue object created for the duration of a Connection.
TemporaryTopic.javaInterface A TemporaryTopic object is a unique Topic object created for the duration of a Connection.
TextMessage.javaInterface A TextMessage object is used to send a message containing a java.lang.String. It inherits from the Message interface and adds a text message body.

This message type can be used to transport text-based messages, including those with XML content.

When a client receives a TextMessage, it is in read-only mode.

Topic.javaInterface A Topic object encapsulates a provider-specific topic name.
TopicConnection.javaInterface A TopicConnection object is an active connection to a publish/subscribe JMS provider.
TopicConnectionFactory.javaInterface A client uses a TopicConnectionFactory object to create TopicConnection objects with a publish/subscribe JMS provider.

A TopicConnectionFactory can be used to create a TopicConnection, from which specialized topic-related objects can be created.

TopicPublisher.javaInterface A client uses a TopicPublisher object to publish messages on a topic.
TopicRequestor.javaClass The TopicRequestor helper class simplifies making service requests.

The TopicRequestor constructor is given a non-transacted TopicSession and a destination Topic.

TopicSession.javaInterface A TopicSession object provides methods for creating TopicPublisher, TopicSubscriber, and TemporaryTopic objects.
TopicSubscriber.javaInterface A client uses a TopicSubscriber object to receive messages that have been published to a topic.
TransactionInProgressException.javaClass

This exception is thrown when an operation is invalid because a transaction is in progress.

TransactionRolledBackException.javaClass

This exception must be thrown when a call to Session.commit results in a rollback of the current transaction.

XAConnection.javaInterface The XAConnection interface extends the capability of Connection by providing an XASession (optional).

The XAConnection interface is optional.

XAConnectionFactory.javaInterface The XAConnectionFactory interface is a base interface for the XAQueueConnectionFactory and XATopicConnectionFactory interfaces.

Some application servers provide support for grouping JTS capable resource use into a distributed transaction (optional).

XAQueueConnection.javaInterface An XAQueueConnection provides the same create options as QueueConnection (optional).
XAQueueConnectionFactory.javaInterface An XAQueueConnectionFactory provides the same create options as a QueueConnectionFactory (optional).

The XATopicConnectionFactory interface is optional.

XAQueueSession.javaInterface An XAQueueSession provides a regular QueueSession, which can be used to create QueueReceiver, QueueSender, and QueueBrowser objects (optional).

The XAQueueSession interface is optional.

XASession.javaInterface The XASession interface extends the capability of Session by adding access to a JMS provider's support for the Java Transaction API (JTA) (optional).
XATopicConnection.javaInterface An XATopicConnection provides the same create options as TopicConnection (optional).
XATopicConnectionFactory.javaInterface An XATopicConnectionFactory provides the same create options as a TopicConnectionFactory (optional).

The XATopicConnectionFactory interface is optional.

XATopicSession.javaInterface An XATopicSession provides a regular TopicSession. which can be used to create TopicSubscriber and TopicPublisher objects (optional).

The XATopicSession interface is optional.

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.