Académique Documents
Professionnel Documents
Culture Documents
After completing this unit, you will be able to: name the participants and explain the concepts of the Java Message Service (JMS) give examples where JMS can be used describe the special features of Message Driven Beans (MDBs) implement general JMS applications and MDBs using the SAP NetWeaver Developer Studio explain the special JMS features in SAP NetWeaver 04
Java Message Service and Message Driven Beans: Course Overview Diagram
<To be taken from the Course Overview unit. Change the highlight to show which unit is now covered.>
JMS is adequate for coupling systems which have to exchange data, but to not depend on the other systems immediate reaction. Scenario: A company has among others two systems. One is located in a call center, one in the accounting department. The call center agents enter new complaints and have the possibility to grant a financial compensation to the customers. If they do so, the system they use will send a message to the accounting system and they can proceed with their work it does not matter to them when the accounting guys will execute the request.
SAP AG 2004, JA 331 / Unit: JMS and MDB / 4
After completing this topic, you will be able to: name the participants involved in the Java Message Service (JMS) explain the basic concepts of JMS implement an application for sending a message
Asynchronous Messaging
Asynchronous messaging can be compared to e-mail communication between people
System 1
Message-Oriented Middleware
System 2
Benefits: Better performance: Avoid waiting for replies Loosely coupling of systems Connection of systems written in different languages
The JMS API defines a vendor independent access to various MOM (JMS based) systems is part of the J2EE platform is defined within the javax.jms package
JMS Destinations
Queue
Point-To-Point
Topic
Publish-Subscribe
Messaging Models
Point-to-Point / Publish-Subcribe
Queue Sender 5 4
3 2 Queue
Queue Receiver 1
Topic Publisher 3
Topic Subscriber 1
1b
Topic Subscriber 2
1. 2. 3.
SAP AG 2004, JA 331 / Unit: JMS and MDB / 10
Point-to-point QueueBrowser
Queue
JMS Provider
QueueBrowsers can see all messages on a Queue regardless of the order QueueBrowsers do NOT consume messages, i.e. all messages will be available for the according receivers A QueueBrowser starts at the end of the Queue and can then iterate over the messages; it cannot go back
Queue Browser
Message Format
Header
Properties
Body
A Message of one of the following types: StreamMessage MapMessage TextMessage ObjectMessage BytesMessage [Message ( has no body)]
Sending a message
Source code / 1
InitialContext iCtx = new InitialContext(); QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) iCtx.lookup("java:comp/env/jms/QConnFactory");
Queue Connection Factory
Queue Connection
QueueSession queueSession = queueConnection.createQueueSession(true, 0); //true -> session is transacted; 0 -> acknowledgement not specified
Queue Session
Queue
Queue Sender
Sending a message
Source code / 2
1 Message message = queueSession.createMessage(); message.setStringProperty("name", "value"); //...
Queue Connection Factory
queueSender.send(message);
1 Queue Sender
Queue
Sending a message
2
<resource-ref> <res-ref-name>jms/QConnFactory</res-ref-name> <res-link>QueueConnectionFactory</res-link> </resource-ref>
Transactions
Sessions may be specified as transacted. Finishing a transaction automatically starts the next. call commit() / rollback() on your session
Sending App 4 3
Receiving App
6 5 Transaction A1
JMS Provider
2 1 Transaction B1 Session B
Session A
Acknowledgement
If a session is not transacted, there are three ways to realize the acknowledgement: AUTO_ACKNOWLEDGE the session acknowledges the message receipt clients have to be prepared to receive the last message more than once DUPS_OK_ACKNOWLEDGE lazy acknowledgement; may result in duplicate messages clients have to be prepared to receive multiple messages more than once CLIENT_ACKNOWLEDGE the client acknowledges; the acknowledgement of one message automatically acknowledges all other messages
You should now be able to: name the participants involved in the Java Message Service (JMS) explain the basic concepts of JMS implement an application for sending a message explain the transaction concept used for JMS
After completing this topic, you will be able to: state the differences between Message Driven Beans (MDBs) and other Enterprise Java Beans explain how messages are passed to MDBs implement an MDB
EJB
Session Beans
Entity Beans
Stateless
Statefull
Synchronous Communication
<<Interface>> MessageListener
<<Interface>> MessageDrivenBean
ExampleMDB
javax.ejb.MessageDrivenBean by this MDBs inherit the methods the container needs to handle them like other EJBs
Transactions
MDBs do not use the usual JMS transaction model; they can make use of distributed transactions
container-managed transaction demarcation The onMessage() method gets one the following attributes
Required: The message receipt and the onMessage() method run within the same, new transaction. NotSupported: The onMessage() method runs without a transaction.
bean-managed transaction demarcation The onMessage() method starts and commits transactions explicit.
Parallel Processing
The EJB Container handles several instances of one MDB at one time server-side concurrent processing All instances are equivalent Each MDB instance runs within its own thread. There is no guarantee that messages are delivered in exact the same order as they are sent.
MDB Instance 1 MDB MDB Instance 2 JMS Provider EJB Container MDB Instance 3
Thread A
Thread B
Thread C
Lifecycle
does not exist
called before deletion //create a new instance setMessageDrivenContext() ejbCreate() ejbRemove()
method-ready pool
onMessage()
Deployment Descriptors
ejb-jar.xml / 1
MDBs are declared in the ejb-jar.xml within the tag <message-driven> EJB related data / Messaging related data EJB name bean class name
EJB related
Messaging related
Deployment Descriptors
ejb-jar.xml / 2
Environment
Deployment Descriptors
ejb-j2ee-engine.xml
You should now be able to: state the differences between Message Driven Beans (MDBs) and other Enterprise Java Beans explain how messages are passed to MDBs implement an MDB
After completing this topic, you will be able to: state the special features regarding the Java Message Service in SAP NetWeaver create a Message Driven Bean with the SAP NetWeaver Developer Studio
Overview
Full implementation of JMS 1.0.2b Integrated in SAP NetWeavers Security concepts Accessing the central user store you can determine who is allowed to administrate JMS objects. For all destinations (Queues & Topics) it can be defined who is allowed to send to or receive from them.
Failover Capability
JMS Connector IDE Support
Failover capability
If the node with the JMS Service running on it crashes, another node will host it.
JMS
JMS
Cluster
Cluster
JMS
Cluster
JMS Connector / 1
Through the JMS Connector it gets transparent for the application which JMS Provider is used.
JMS App
JMS App
JMS App
XML
JMS Connector
JMS Provider
JMS Connector / 2
[Source code / standard deployment descriptor]
<resource-ref> <res-ref-name>jms/QConnFactory</res-ref-name> <res-link>QueueConnectionFactory</res-link> </resource-ref>
IDE Support
IDE Support
Deployment descriptor
MDB class
Business Logic
IDE Support
Bidirectional Editing
You should now be able to: state the special features regarding the Java Message Service in SAP NetWeaver create a Message Driven Bean with the SAP NetWeaver Developer Studio
You should now be able to: name the participants and explain the concepts of the Java Message Service (JMS) give examples where JMS can be used describe the special features of Message Driven Beans (MDBs) implement general JMS applications and MDBs using the SAP NetWeaver Developer Studio explain the special JMS features in SAP NetWeaver 04