ja331 - unit jms and mdb
TRANSCRIPT
-
8/12/2019 Ja331 - Unit Jms and Mdb
1/39
Java Message Service &
Message Driven Beans
JA 331 - SAP JavaOpen IntegrationTechnologies
-
8/12/2019 Ja331 - Unit Jms and Mdb
2/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 2
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:Unit Objectives
-
8/12/2019 Ja331 - Unit Jms and Mdb
3/39
-
8/12/2019 Ja331 - Unit Jms and Mdb
4/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 4
JMS is adequate for coupling systems which have to
exchange data, but to not depend on the other
systems immediate reaction.
Scenario:
A company hasamong otherstwo 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, thesystem they use will send a message to the
accounting system and they can proceed with their
workit does not matter to them when the
accounting guys will execute the request.
Java Message Service and Message Driven Beans:Business Scenario
-
8/12/2019 Ja331 - Unit Jms and Mdb
5/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 5
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
explain the transaction concept used for JMS
Java Message Service: Topic Objectives
-
8/12/2019 Ja331 - Unit Jms and Mdb
6/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 6
Asynchronous Messaging
Benefits:
Better performance: Avoid waiting for replies
Loosely coupling of systems
Connection of systems written in different languages
Message-OrientedMiddleware
System 1 System 2
Asynchronous messaging can be compared to e-mail
communication between people
-
8/12/2019 Ja331 - Unit Jms and Mdb
7/39 SAP AG 2004, JA 331 / Unit: JMS and MDB / 7
Java Message Service
The Java Message Service is a Message-Oriented Middleware
(MOM)and thus allows to decouple producers and consumers
of messages
The JMS API
defines a vendor independent access to variousMOM (JMS based) systems
is part of the J2EE platform
is defined within the javax.jmspackage
-
8/12/2019 Ja331 - Unit Jms and Mdb
8/39 SAP AG 2004, JA 331 / Unit: JMS and MDB / 8
JMS Providers provide an implementationof the JMS API
Web Application Server
JMS Clients use the implementation and can be
Producers(send messages)
Consumers(receive messages)
JMS Providers & Clients
-
8/12/2019 Ja331 - Unit Jms and Mdb
9/39 SAP AG 2004, JA 331 / Unit: JMS and MDB / 9
JMS Destinations
Queue Topic
Point-To-Point
One registered receiver per
message
Publish-Subscribe
Many receivers per message
possible
2 kinds of subscription
Non-durable
Durable
Durability by store-and-forward
messaging
FIFO
M i M d l
-
8/12/2019 Ja331 - Unit Jms and Mdb
10/39 SAP AG 2004, JA 331 / Unit: JMS and MDB / 10
JMS Provider
Messaging ModelsPoint-to-Point / Publish-Subcribe
Queue
Sender QueueReceiver
Queue
23
145
1 2 3
1. Messages to be sent
2. Messages waiting in the Queue
3. Messages being consumed
Topic
2
Topic
Publisher
3
Topic
Subscriber 2
Topic
Subscriber 1
1a
1b
-
8/12/2019 Ja331 - Unit Jms and Mdb
11/39
-
8/12/2019 Ja331 - Unit Jms and Mdb
12/39 SAP AG 2004, JA 331 / Unit: JMS and MDB / 12
Message Format
Header
Properties
Body
Administrative Information;
key-value-pairs
Additional Information;
key-value-pairs
A Message of one of the following types:StreamMessage
MapMessage
TextMessageObjectMessage
BytesMessage
[Message( has no body)]
Some may be
disabled to
improve
performance
S di
-
8/12/2019 Ja331 - Unit Jms and Mdb
13/39 SAP AG 2004, JA 331 / Unit: JMS and MDB / 13
InitialContext iCtx = new InitialContext();
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)iCtx.lookup("java:comp/env/jms/QConnFactory");
QueueConnection queueConnection =
queueConnectionFactory.createQueueConnection();
QueueSession queueSession =
queueConnection.createQueueSession(true, 0);
//true -> session is transacted; 0 -> acknowledgement
not specified
Queue queue =
(Queue)iCtx.lookup("java:comp/env/jms/myQueue");
QueueSender queueSender =
queueSession.createSender(queue);
Sending a messageSource code / 1
Queue
ConnectionFactory
Queue
Session
Queue
Sender
Queue
Connection
Queue
S di
-
8/12/2019 Ja331 - Unit Jms and Mdb
14/39 SAP AG 2004, JA 331 / Unit: JMS and MDB / 14
Message message = queueSession.createMessage();
message.setStringProperty("name", "value");
//...
queueSender.send(message);
Sending a messageSource code / 2
Queue
Connection
Factory
Queue
Session
Queue
Sender
Queue
Connection
Queue
1
2
1
2
S di
-
8/12/2019 Ja331 - Unit Jms and Mdb
15/39 SAP AG 2004, JA 331 / Unit: JMS and MDB / 15
Sending a messageLogical names and Mapping
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)
initialContext.lookup("java:comp/env/jms/QConnFactory");
jms/QConnFactory
...
jms/QConnFactory
QueueConnectionFactory
Source Code
Standard
deployment
descriptor
Vendordeployment
descriptor
1
2
-
8/12/2019 Ja331 - Unit Jms and Mdb
16/39 SAP AG 2004, JA 331 / Unit: JMS and MDB / 16
Sessionsmay be specified as transacted.
Finishing a transaction automatically starts the next.
call commit()/ rollback()on your session
Receiving
App
JMS Provider
Transactions
Sending
App
Session A Session B
4 3
Transaction B1
2 1
Transaction A1
6 5
-
8/12/2019 Ja331 - Unit Jms and Mdb
17/39 SAP AG 2004, JA 331 / Unit: JMS and MDB / 17
Acknowledgement
If a session is not transacted, there are three ways to realize theacknowledgement:
AUTO_ACKNOWLEDGEthe session acknowledges the message receipt
clients have to be prepared to receive the last messagemore than once
DUPS_OK_ACKNOWLEDGElazy acknowledgement; may result in duplicate messages
clients have to be prepared to receive multiplemessages more than once
CLIENT_ACKNOWLEDGE
the client acknowledges; the acknowledgement of onemessage automatically acknowledges all other messages
Flag: JMSRedelivered(message header) for resent messages
-
8/12/2019 Ja331 - Unit Jms and Mdb
18/39 SAP AG 2004, JA 331 / Unit: JMS and MDB / 18
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
Java Message Service: Topic Summary
-
8/12/2019 Ja331 - Unit Jms and Mdb
19/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 19
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
Message Driven Beans: Topic Objectives
-
8/12/2019 Ja331 - Unit Jms and Mdb
20/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 20
Enterprise Java Beans Overview
Session
Beans
Entity
Beans
EJB
Stateless Statefull ContainerManaged
Persistence
BeanManaged
Persistence
Asynchronous
Communication
Message Driven
Beans
Synchronous Communication
-
8/12/2019 Ja331 - Unit Jms and Mdb
21/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 21
Message Driven Beans
came new with EJB 2.0
are handled by the EJB Container, which acts as a JMS ClientMDBs can consume messages (and optionally produce
them)
will be assigned to one Topic or Queue
are server-side components(like other EJBs) and consist of
the bean class
two deployment descriptors
nointerfaces (home, remote)
MDBs are accessed by sending messages to the accordingQueue or Topic
are stateless
-
8/12/2019 Ja331 - Unit Jms and Mdb
22/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 22
The Dual Nature of MDBs
EnterpriseBean
ExampleMDB
MessageDrivenBean
MessageListener
The business logic is put
into the onMessage() method.
javax.ejb.MessageDrivenBean
by this MDBs inherit the
methods the container needs to
handle them like other EJBs
javax.jms.MessageListener
provide an asynchronous
receipt of JMS messages
T ti
-
8/12/2019 Ja331 - Unit Jms and Mdb
23/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 23
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 receiptand theonMessage()methodrun 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.
P ll l P i
-
8/12/2019 Ja331 - Unit Jms and Mdb
24/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 24
Parallel Processing
The EJB Container handles several instances of one MDB at one
time server-side concurrentprocessing
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.
JMS ProviderEJB
Container
MDB
Instance 1Thread A
MDB
Instance 2Thread B
MDB
Instance 3Thread C
MDB
Lif l
-
8/12/2019 Ja331 - Unit Jms and Mdb
25/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 25
Lifecycle
does not
exist
method-ready
pool
ejbRemove()//create a new instance
setMessageDrivenContext()
ejbCreate()
onMessage()
called before
deletion
invoked on
message
receipt
called after
creation
Deployment Descriptors
-
8/12/2019 Ja331 - Unit Jms and Mdb
26/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 26
Deployment Descriptorsejb-jar.xml / 1
MDBs are declared in the ejb-jar.xmlwithin the tag
EJB relateddata / Messaging relateddata
EJB name
bean class name
transaction demarcation type
environment entries used by the MDB
The JMS destination type the MDB listens to
EJB related
Messaging
related
Deployment Descriptors
-
8/12/2019 Ja331 - Unit Jms and Mdb
27/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 27
Deployment Descriptorsejb-jar.xml / 2
Name / class
Destination type
Environment
Deployment Descriptors
-
8/12/2019 Ja331 - Unit Jms and Mdb
28/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 28
Deployment Descriptorsejb-j2ee-engine.xml
Vendor specific descriptor
contains additional information JMS information
the concrete destination of the MDB
the concrete ConnectionFactory used
M D i B T i S
-
8/12/2019 Ja331 - Unit Jms and Mdb
29/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 29
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
Message Driven Beans: Topic Summary
JMS @ SAP NetWea er 04 Topic Objecti es
-
8/12/2019 Ja331 - Unit Jms and Mdb
30/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 30
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
JMS @ SAP NetWeaver 04: Topic Objectives
Overview
-
8/12/2019 Ja331 - Unit Jms and Mdb
31/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 31
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 definedwho is allowed to send to or receive from them.
Failover Capability
JMS Connector
IDE Support
Failover capability
-
8/12/2019 Ja331 - Unit Jms and Mdb
32/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 32
Failover capability
Cluster
JMS
If the node with the JMS Service running on it crashes, another
node will host it.
Cluster
JMS
Cluster
JMS
JMS Connector / 1
-
8/12/2019 Ja331 - Unit Jms and Mdb
33/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 33
JMS Connector / 1
Through the JMS Connector it gets transparent for the application
which JMS Provider is used.
JMS App JMS App JMS App
JMS Provider
JMS ConnectorXML
JMS Connector / 2
-
8/12/2019 Ja331 - Unit Jms and Mdb
34/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 34
JMS Connector / 2
jms/QConnFactory
QueueConnectionFactory
QueueConnectionFactory
...
jmsfactory/default/QueueConnectionFactory
Vendor
deployment
descriptor
JMS Connectordeployment
descriptor
JMS Provider /
JNDI
[Source code / standard deployment descriptor]
1
2
IDE Support
-
8/12/2019 Ja331 - Unit Jms and Mdb
35/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 35
ppCreating a new MDB / 1
IDE Support
-
8/12/2019 Ja331 - Unit Jms and Mdb
36/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 36
ppCreating a new MDB / 2
Deployment
descriptor
MDB classBusiness Logic
IDE Support
-
8/12/2019 Ja331 - Unit Jms and Mdb
37/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 37
ppBidirectional Editing
JMS @ SAP NetWeaver 04: Topic Summary
-
8/12/2019 Ja331 - Unit Jms and Mdb
38/39
SAP AG 2004, JA 331 / Unit: JMS and MDB / 38
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
JMS @ SAP NetWeaver 04: Topic Summary
Java Message Service and Message Driven Beans:
-
8/12/2019 Ja331 - Unit Jms and Mdb
39/39
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 NetWeaver04
Unit Summary