Establishing a Brand-driven Message Architecture WebVisions NYC
Message Driven Beans
-
Upload
junksreddy-reddy -
Category
Documents
-
view
8 -
download
0
description
Transcript of Message Driven Beans
-
5/21/2018 Message Driven Beans
1/23
SCOT
Message Driven Beans
Using JMS
Swapnil Shrivastava
-
5/21/2018 Message Driven Beans
2/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 2
Challenges with RMI-IIOP
Performancemust wait while the serverperforms processing
ReliabilityWhen RMI-IIOP calls theserver, it has to be running
Support for multiple senders and receiversnot possible.
-
5/21/2018 Message Driven Beans
3/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 3
Messaging
Receive messages from one or more
message producers and broadcast it to one
or more message consumers.
Support asynchronous programming.
Application
Message
Oriented
MiddlewareApplication
-
5/21/2018 Message Driven Beans
4/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 4
Message Oriented Middleware
Software infrastructure that supports
messaging.
Example
Sonic MQ
IBM MQSeries
BEA Tuxedo/Q
Microsoft MSMQ
-
5/21/2018 Message Driven Beans
5/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 5
Challenges addressed
PerformanceA messaging client does not needto block when performing a request.
ReliabilityIf your MOM supports guaranteed
delivery , you can send a message and know for
sure it will reach the destination, even if the
consumer is not available.
Support for multiple senders and receivers
possible..
-
5/21/2018 Message Driven Beans
6/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 6
Messaging Domains
It is the style of messaging which is chosen
to send messages.
Types :
Publish/Subscribe (Pub/Sub) Domain.
Point-to-Point (PTP) Domain.
-
5/21/2018 Message Driven Beans
7/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 7
Publish/Subscribe
Many message producers talking to many messageconsumers.
It is an implementation of distributed event drivenprocessing model.
Publisher send messages to topic in JMS.
Consumers who are interested in message
subscribe to message topic. Topic are persistent stores located at JMS
destination.
-
5/21/2018 Message Driven Beans
8/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 8
Publish/Subscribe
Producer1
Producer 2 Consumer 2
Consumer 1Topic subscribe
deliver
subscribe
deliver
publishes
publishes
-
5/21/2018 Message Driven Beans
9/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 9
Point-to-Point
Single consumer for each message.
Multiple producers can send messages to
the queue but each message is delivered tosingle consumer.
Messages are sent to queue from which they
are distributed to consumers in FIFO order. Queue are persistent stores located at JMS
destination.
-
5/21/2018 Message Driven Beans
10/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 10
Point-to-Point
Producer Consumersends
acknowledges
consumes
Queue
-
5/21/2018 Message Driven Beans
11/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 11
JMS
JMS is a messaging standard.
Allows applications to create,send ,receive and
read messages. JMS consists of
JMS API : to write code to send and receive messages.
JMS SPI : where we plug in JMS drivers.
Low level topology issues are abstracted from the
developer.
-
5/21/2018 Message Driven Beans
12/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 12
JMS Programming Model
Locate JMS driver.
Create a JMS connection.
Create a JMS Session.
Locate a JMS destination.
Create a JMS producer or a JMS consumer.
Send or receive your message.
-
5/21/2018 Message Driven Beans
13/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 13
JMS Architecture
Connection
FactoryConnection Session
Message
Consumer
Message
Producer
Message
Queue
or Topic
Queue
or Topic
creates creates
creates
creates
creates
Sends to
Gets
from
-
5/21/2018 Message Driven Beans
14/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 14
JMS-EJB Integration
To allow EJB components to benefit from
value propositions of messaging such as
Non blocking clients
N-ary communication
EJB 2.0 introduced Message Driven Beans
for JMS-EJB Integration.
-
5/21/2018 Message Driven Beans
15/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 15
Message Driven Beans
MDB is a special EJB component that can
receive JMS messages.
MDB consumes messages from queues ortopics that are sent by any valid JMS client.
JMS API is used to send messages to MDB.
-
5/21/2018 Message Driven Beans
16/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 16
Message Driven
Bean Instance
Client JMS Destination
Message Driven
Bean Pool
Send/
publishes
EJB Server
Message Driven Beans
-
5/21/2018 Message Driven Beans
17/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 17
MDB Characteristics
Doesnt have home interface, remote
interface,local interface and local home
interface. Have one loosely typed business method.
Do not have any return values.
Cannot send exceptions back to the client. They are stateless.
Can be durable or non durable subscribers.
-
5/21/2018 Message Driven Beans
18/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 18
Message Driven Bean Interface
public interface javax.jms.MessageListener
{
public void onMessage(Message message);}
public interface javax.ejb.MessageDrivenBean extends EnterpriseBean
{
public void ejbRemove()throws EJBException;
public void setMessageDrivenContext(MessageDrivenContext ctx)
throws EJBException;
}
SCO
-
5/21/2018 Message Driven Beans
19/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 19
MDB Ingredients
Message Driven Beans implements both
MessageDrivenBean and MessageListener
interface. Consistes of:
MessageDrivenBean class.
Deployment Descriptor.
Vendor Specific Files.
SCOT
-
5/21/2018 Message Driven Beans
20/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 20
Example
SCOT
-
5/21/2018 Message Driven Beans
21/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 21
MDB Object Model
java.io.Serializable
javax.ejb.EnterpriseBean
javax.ejb.MessageDrivenBean
Bean Implement
Class
Comes with Java2 platform
Comes with EJB Distribution
Written by developer
javax.jms.MessageListener
SCOT
-
5/21/2018 Message Driven Beans
22/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 22
Message Driven Bean Life Cycle
Does Not Exist
Pooled
1: newInstance()
2: setMessageDrivenContext()
3: ejbCreate()
ejbRemove()
onMessage()
SCOT
-
5/21/2018 Message Driven Beans
23/23
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 23
References
Mastering Enterprise Java Beans
J2EE 1.4 Tutorials
Professional Java Server Programming,
J2EE Edition