05_JMS - Andrew.cmu.edu

Download Report

Transcript 05_JMS - Andrew.cmu.edu

Organizational Communications and
Distributed Object Technologies
Lecture 5: JMS
95-702 OCT
Master of Information System
Management
1
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
95-702 OCT
coupling.
2
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.
95-702 OCT
Master of Information System
Management
3
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.
95-702 OCT
Guarantees
may be configured.
Master of Information System
Management
4
Main Players
• Messaging clients (produce and
consume messages)
• Message destinations (to send and
receive messages)
• A JMS Message Provider
95-702 OCT
Master of Information System
Management
5
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
95-702 OCT
6
of Information System
or IP Master
multicasting.
Management
JMS API from Sun’s
Tutorial
Connection Factory
creates
Connection
creates
Message Producer
Session
Message Consumer
creates
sends to
Destination
creates
Message
95-702 OCT
Master of Information System
Management
receives from
Destination
7
JMS API from Sun’s
Tutorial
Connection Factory
creates
Connection
creates
Message Producer
Session
Message Consumer
creates
sends to
Destination
creates
Message
receives from
Destination
Subtypes provide
implementations
for different types
of content.
95-702 OCT
Master of Information System
Management
8
JMS API from Sun’s
Tutorial
Attach
Connection Factory
creates
Connection
creates
Message Producer
Session
Message Consumer
creates
sends to
Destination
creates
Message
95-702 OCT
Master of Information System
Management
MessageListeners
that implement
the onMessage()
method. Or, use
a Message Driven
Bean.
receives from
Destination
9
JMS API from Sun’s
QueueConnection
Perform a JNDI lookUp() Tutorial
Factory or
for this administrated
object.
Connection Factory
creates
TopicConnection
Factory
Connection
creates
Message Producer
creates
Session
Message Consumer
creates
sends to
Destination
Message
Perform a JNDI lookUp()
for this administrated
object.
95-702 OCT
Master of Information System
Management
receives from
Destination
Destination resources may
be Queues or Topics.
10
JMS API from Sun’s
Tutorial
A live connection to the
provider.
Connection Factory
creates
May be a
QueueConnection or a
TopicConnection
Connection
creates
Message Producer
Session
creates
sends to
Destination
Message Consumer
Message
receives from
Destination
Must be ‘started’
before receiving
messages.
95-702 OCT
Master of Information System
Management
11
JMS API from Sun’s
Tutorial
Connection Factory
The producer writes.
QueueSender or
TopicPublisher
creates
Connection
creates
Message Producer
Session
Message Consumer
creates
sends to
Destination
creates
Message
95-702 OCT
Master of Information System
Management
The consumer
retrieves.
QueueReceiver
TopicSubscriber
receives from
Destination
12
JMS API from Sun’s
Tutorial
Connection Factory
creates
Connection
creates
Message Producer
creates
Session
Message Consumer
creates
sends to
Destination
Message
QueueSession or
ToipcSession
95-702 OCT
Master of Information System
Management
receives from
Destination
A single, serialized flow of messages
between the client and a provider.
This flow may be transacted.
13
Java Messaging
Architecture (Centralized)
Client
Application
Client
Application
Message
Broker
Client
Application
Client
Application
Client
Application
95-702 OCT
Master of Information System
Management
14
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.
95-702 OCT
Master of Information System
Management
15
JMS Transaction
Begin transaction
send M1
send M2
send M3
commit or rollback
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.
95-702 OCT
Master of Information System
Management
16
JMS Acknowledgements
Client
Application
Client
Application
I got it!
M1
Message
Broker
95-702 OCT
Master of Information System
Management
Connections
contain sessions with
acknowledgement modes.
These are low level
acknowldgements, not
associated with replies that
follow requests.
17
JMS Acknowledgements
Client
Application
Client
Application
I got it!
M1
Message
Broker
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
95-702 OCT
to the broker.
Call
acknowledge() method on the message received.
18
Master of Information System
Management
JMS Between
Organizations(1)
Client
Application
JMS
Message
Broker
MQSeries
Message
Broker
JMS Bridge
Products exist allowing these two brokers to talk.
This degree of interconnectedness may be inappropriate.
95-702 OCT
Master of Information System
Management
19
JMS Between
Organizations(2)
Browser
Client
Client
Application
HTTP
Servlet
Client
Application
JMS
Message
Broker
Web Components may act as JMS clients.
95-702 OCT
Master of Information System
Management
20
Web
Client
Using SOAP
HTTP
JMS Between
Organizations(2)
Web
Service
Client
Application
Client
Application
JMS
Message
Broker
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.
95-702 OCT
Master of Information System
Management
21