Overview 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.
Part 1: Enterprise Messaging and JMS
Enterprise messaging Application A Application B Messaging API Messaging Clients - Oriented Middleware Messaging API Messaging Clients
Tightly Coupled RPC Business Application A RPC Client/ Business Application B RPC Client/ Business Application D RPC Client/ Requires n * (n-1) / 2 connections Business Application C RPC Client/
JMS messaging Centralized message server (hub and spoke) Decentralized message server (IP multicast) JMS Client JMS Client JMS Client Application A JMS Client Local "server" Router Local "server" Local "server" Local "server" JMS Client JMS Client JMS Client JMS Client JMS Client JMS Client Application B Application C Application D
The J2EE platform Client Application J2EE Platform EJB Container Web Container Application Client Container JMS JDBC Database
Part 2: JMS Concepts and Coding
Wholesaler and retailer Wholesaler Update price (publish) Order product (send) Retailer 1 Retailer 2
JMS features Standard Java API delivery modes Two messaging models Transactions Reliability levels Persistent messaging
JMS messaging domains Publish and subscribe Many consumers per message Point-to-point One consumer per message
Publisher Publish and subscribe: Supply chain management Topic Subscriber
Point-to-point: Order and fulfillment Sender Queue Receiver Need Supplies Goods Shipped
JMS components JMS Client Connection Session JMS Client Connection Session Producer Destination Consumer
Connections and sessions JMS Client Connection Session Session A connection connects to a message server. You can create one or more sessions within a connection. Session
Creating connections and sessions JMS Client ConnectionFactory JNDI Store ConnectionFactories Destinations create Connection Session Session Session
JMS message types type Text Object Map Stream Bytes body No body A standard Java string A serializable Java object A set of name/value pairs where values are Java primitives A stream of Java primitives A stream of uninterpreted bytes
Creating a message TopicSession createstream( ); QueueSession Stream createtext( ); Text
JMS message headers Automatically assigned headers JMSDestination JMSDeliveryMode JMSID JMSTimestamp JMSExpiration JMSRedelivered JMSPriority Developer-assigned headers JMSReplyTo JMSCorrelationID JMSType
Producers, consumers, and destinations Producer Consumer Bind to destination Bind to destination Read message Send message Destination Consume message
Creating destinations JNDI Store JMS Client ConnectionFactories Destinations lookup Topic Queue
Producing a message Session create message create Destination Producer produce message
Consuming messages Incoming messages acknowledge Incoming messages Listener on(message); acknowledge Consumer receive();
Asynchronous message delivery Incoming messages Listener on(message); acknowledge
Using receive( ) Incoming messages Consumer receive(); acknowledge
Filtering with message selector Publisher Departments.Sales JMSPriority = 2 Pipeline = 20000 Subscriber Departments.Sales Pipeline > 15000 delivered not delivered Subscriber Departments.Sales Pipeline > 20000 Subscriber Departments.Sales JMSPriority > 5 not delivered delivered Subscriber Departments.Sales JMSPriority >= 2 AND Pipeline > 10000
Browsing a queue QueueBrowser 1 getenumeration(); 2 Enumeration nextelement(); 3 4
Accessing message content get<type>(name); Map Text Object Stream Bytes gettext(); getobject(); read<type>();
Part 3: Guaranteed messaging
Guaranteeing message delivery Producer PERSISTENT message Acknowledge message Durable Subscriber Or QueueReceiver Persistent store removed after acknowledgment
Persistent and non-persistent messages Non-persistent message not guaranteed to survive provider failure Persistent message guaranteed to survive provider failure Persistent store
Acknowledgement modes AUTO Consumer I got another message! It might be easy for you to tell me that for every message, but you are using a lot of bandwidth. CLIENT I received all messages up to this point. Where have you been? I have been waiting to delete 50 messages. DUPS_OK Okay, I might seem lazy to you, but it is not important to me if there are some duplicates. When you are lazy like this, I might have to deliver some messages more than once.
Durable subscribers Publisher PERSISTENT message Durable Subscriber1 (connected) Undelivered messages delivered to Subscriber2 when reconnected Persistent store Durable Subscriber2 (not connected)
Redelivered messages Before message server receives acknowledgement: server has failed and restarted OR Consumer has failed and restarted Consumer JMSRedelivered=true
Part 4: Transactions and recovery
Transacted session: Producer Before commit( ) Producer Transacted session Upon commit( ) Consumer
Transacted session: Consumer Before commit( ) 1 Deliver messages Consumer 2 Consume messages Upon commit( ) 2 Delete messages if all recipients have acknowledged Acknowledge messages 1 Consumer
Distributed transaction support JMS Client XAConnectionFactory JNDI Store ConnectionFactories Destinations create XAConnection XASession XASession XASession
Recovering from a lost connection Client runtime ExceptionListener Reconnect onexception()
Understanding the Java Service: Conclusion