210 likes | 291 Views
Organizational Communications and Distributed Object Technologies. Lecture 5: JMS. Java Message Service. Introduced by Sun J2EE in 1999 See Chapter 10 of “Java Enterprise in a Nutshell” by Farley, Crawford and Flanagan
E N D
Organizational Communications and Distributed Object Technologies Lecture 5: JMS Master of Information System Management
Java Message Service • Introduced by Sun J2EE in 1999 • See Chapter 10 of “Java Enterprise in a Nutshell” by Farley, Crawford and Flanagan • Web Services, CORBA, and Java RMI use, by default, synchronous communications. • In the synchronous approach, the client makes a call and waits for a response. This is an example of tight coupling. • In this respect, JMS promotes loose coupling. Master of Information System Management
Java Message Service • An API for performing asynchronous messaging. • Uses the provider architecture. • It is an abstraction API like JNDI and JDBC. • Sits on top of Message Oriented Middleware (MOM). • The MOM might be IBM MQ Series, Sonic MQ, Tibco EMS or Apache’s Active MQ. • Microsoft has a non-JMS MOM called MSMQ. • IBM’s WebSphere Application Server offers a JMS implementation that is reused by WebSphere ESB. The ESB adds features. • We’ll be using the provider from Sun that is installed with Netbeans and Glassfish V2. Master of Information System Management
JMS Communications • Point to point Asynchronous. Similar to email. Guaranteed delivery. • Publish Subscribe Asynchronous. Similar to a bulletin board or newsgroup (one to many). One publishes to a topic and many subscribe to a topic. Guarantees may be configured. Master of Information System Management
Main Players • Messaging clients (produce and consume messages) • Message destinations (to send and receive messages) • A JMS Message Provider Master of Information System Management
Where Do The Players Live? • Typically, JMS would be deployed within an enterprise. • The enterprise has administrative control over the entire environment. • It may be a centralized or decentralized deployment. • In the decentralized case, queuing logic is distributed to clients. • In the centralized case, queuing logic is centralized (hub and spoke). • The provider may use TCP/IP, UDP/IP or IP multicasting. Master of Information System Management
JMS API from Sun’s Tutorial Connection Factory Connection Message Producer Session Message Consumer Destination Message Destination creates creates creates creates sends to receives from Master of Information System Management
JMS API from Sun’s Tutorial Connection Factory Connection Message Producer Session Message Consumer Destination Message Destination creates creates creates creates sends to receives from Subtypes provide implementations for different types of content. Master of Information System Management
JMS API from Sun’s Tutorial Attach MessageListeners that implement the onMessage() method. Or, use a Message Driven Bean. Connection Factory Connection Message Producer Session Message Consumer Destination Message Destination creates creates creates creates sends to receives from Master of Information System Management
JMS API from Sun’s Tutorial QueueConnection Factory or TopicConnection Factory Perform a JNDI lookUp() for this administrated object. Connection Factory Connection Message Producer Session Message Consumer Destination Message Destination creates creates creates creates sends to receives from Destination resources may be Queues or Topics. Perform a JNDI lookUp() for this administrated object. Master of Information System Management
JMS API from Sun’s Tutorial A live connection to the provider. May be a QueueConnection or a TopicConnection Connection Factory Connection Message Producer Session Message Consumer Destination Message Destination creates creates creates sends to receives from Must be ‘started’ before receiving messages. Master of Information System Management
JMS API from Sun’s Tutorial Connection Factory Connection Message Producer Session Message Consumer Destination Message Destination The consumer retrieves. QueueReceiver TopicSubscriber The producer writes. QueueSender or TopicPublisher creates creates creates creates sends to receives from Master of Information System Management
JMS API from Sun’s Tutorial Connection Factory Connection Message Producer Session Message Consumer Destination Message Destination creates creates creates creates sends to receives from A single, serialized flow of messages between the client and a provider. This flow may be transacted. QueueSession or ToipcSession Master of Information System Management
Java Messaging Architecture (Centralized) Client Application Client Application Message Broker Client Application Client Application Client Application Master of Information System Management
Java Messaging Architecture Client Application Client Application Message Broker Connection Broker located through JNDI. Establish a connection through a connection factory. Create sessions from the connection. Sessions have transactional characteristics and acknowledgement modes. Master of Information System Management
Begin transaction send M1 send M2 send M3 commit or rollback JMS Transaction Client Application Client Application Message Broker Connections contain transacted sessions M1 M2 M3 Messages are staged by the broker until the commit. After commit the message may be delivered to other clients. Upon rollback, the messages are disposed. Master of Information System Management
JMS Acknowledgements Client Application Client Application I got it! Message Broker Connections contain sessions with acknowledgement modes. These are low level acknowldgements, not associated with replies that follow requests. M1 Master of Information System Management
JMS Acknowledgements Client Application Client Application I got it! Message Broker M1 AUTO_ACKNOWLEDGE If a synchronous client receives the message requested it informs the broker automatically. If an asynchronous client receives the message it informs the broker automatically. CLIENT_ACKNOWLEDGEMENT The client program is responsible for sending an acknowledgement to the broker. Call acknowledge() method on the message received. Master of Information System Management
JMS Between Organizations(1) Client Application MQSeries Message Broker JMS Message Broker JMS Bridge Products exist allowing these two brokers to talk. This degree of interconnectedness may be inappropriate. Master of Information System Management
JMS Between Organizations(2) Browser Client Client Application HTTP Servlet Client Application JMS Message Broker Web Components may act as JMS clients. Master of Information System Management
JMS Between Organizations(2) Web Client Using SOAP Client Application Web Service Client Application JMS Message Broker HTTP Web Components may act as JMS clients. In this case, a web services may expose methods to RPC style clients. Or, the web services may collect an XML document from the Web client and pass data to the JMS broker. This is less tightly coupled than connecting two JMS providers with a bridge. Master of Information System Management