Title: Understanding the Java Message Service
1Understanding the Java Message Service
Andreas Taber Systems Engineer Sonic Software
2Overview
- Describe the concepts and some practical
applications of messaging. - Describe the concepts and basic structure of JMS.
- Write simple JMS messaging code using the publish
and subscribe and point-to-point domains. - Discuss advanced JMS issues such as guaranteed
messaging, transactions, reliability, and
recovery.
3Part 1 Enterprise Messaging and JMS
4Enterprise messaging
5Tightly Coupled RPC
Requires n (n-1) / 2 connections
6JMS messaging
- Centralized message server (hub and spoke)
Decentralized message server (IP multicast)
7The J2EE platform
J2EE Platform
8JMS and Web Services
- Program internet clients with standardized JMS
and JAXM interface - Send SOAP, ebXML, and custom XML messages through
the internet - Route internet messages to the enterprise message
bus - Use XSLT to transform messages to standard
formats - Deliver messages to JMS applications for
processing
9Part 2 JMS Concepts and Coding
10Wholesaler and retailer
Update price (publish)
Message Server
Order product (send)
11JMS features
- Standard Java API
- Message delivery modes
- Two messaging models
- Transactions
- Reliability levels
- Persistent messaging
12JMS messaging domains
- Publish and subscribe
- Many consumers per message
- Point-to-point
- One consumer per message
13Publish and subscribe Supply chain management
14Point-to-point Order and fulfillment
Queue
Receiver
Need Supplies
Goods Shipped
15JMS components
JMS Client
JMS Client
Connection
Connection
Session
Session
Producer
Consumer
Message Server
Message
Destination
Message
16Connections and sessions
JMS Client
- A connection connects to a message server.
- You can create one or more sessions within a
connection.
Connection
Session
Session
Session
17Creating connections and sessions
JMS Client
ConnectionFactory
create
JNDI Store
Message Server
Connection
ConnectionFactories Destinations
Session
Session
Session
18JMS message types
19Creating a message
20JMS message headers
- Automatically assigned headers
- JMSDestination
- JMSDeliveryMode
- JMSMessageID
- JMSTimestamp
- JMSExpiration
- JMSRedelivered
- JMSPriority
- Developer-assigned headers
- JMSReplyTo
- JMSCorrelationID
- JMSType
21Producers, consumers, and destinations
Producer
Consumer
Bind to destination
Bind to destination
Read message
Message Server
Send message
Consume message
Destination
22Creating destinations
JMS Client
JNDI Store
Message Server
Topic
ConnectionFactories Destinations
lookup
Queue
23Producing a message
create message
Session
create
Message
Destination
MessageProducer
produce message
24Consuming messages
Incoming messages
acknowledge
Message Server
Incoming messages
acknowledge
25Asynchronous message delivery
MessageListener
onMessage(message)
Message Server
Incoming messages
acknowledge
26Using receive( )
MessageConsumer
Message receive()
Message Server
Incoming messages
acknowledge
27Filtering with message selector
Publisher
Departments.Sales
JMSPriority 2 Pipeline 20000
not delivered
Subscriber
delivered
Subscriber
Message Server
Departments.Sales Pipeline gt 20000
Departments.Sales Pipeline gt 15000
not delivered
delivered
Subscriber
Subscriber
Departments.Sales JMSPriority gt 5
Departments.Sales JMSPriority gt 2 AND Pipeline gt
10000
28Browsing a queue
Message1
QueueBrowser
Message2
getEnumeration()
Message3
Enumeration
nextElement()
Message4
29Accessing message content
Message
getlttypegt(Name)
TextMessage
MapMessage
ObjectMessage
StreamMessage
BytesMessage
getText()
getObject()
readlttypegt()
30Part 3 Guaranteed messaging
31Guaranteeing message delivery
Durable Subscriber Or QueueReceiver
PERSISTENT message
Message Server
Producer
Acknowledge message
Persistent store
Message removed after acknowledgment
32Persistent and non-persistent messages
Non-persistent message not guaranteed to survive
provider failure
Message Server
Persistent message guaranteed to survive provider
failure
Persistent store
33Acknowledgement modes
Consumer
Server
AUTO
CLIENT
DUPS_OK
34Durable subscribers
Durable Subscriber1 (connected)
PERSISTENT message
Message Server
Publisher
Durable Subscriber2 (not connected)
Persistent store
Undelivered messages delivered to Subscriber2
when reconnected
35Redelivered messages
- Before message server receives acknowledgement
- Message server has failed and restarted
- OR
- Consumer has failed and restarted
36Part 4 Transactions and recovery
37Transacted session Producer
Before commit( )
Message Server
Producer
Transacted session
Upon commit( )
Message Server
Consumer
38Transacted session Consumer
Before commit( )
Message Server
Consumer
Deliver messages
Consume messages
Upon commit( )
Message Server
Consumer
Acknowledge messages
Delete messages if all recipients have
acknowledged
39Distributed transaction support
JMS Client
XAConnectionFactory
create
JNDI Store
Message Server
XAConnection
ConnectionFactories Destinations
XASession
XASession
XASession
40Recovering from a lost connection
41Understanding the Java Message Service Conclusion