210 likes | 415 Views
Message Driven Beans. Celsina Bignoli bignolic@smccd.net. Issues with RMI-IIOP. Performance Client must wait for server response Reliability If server crashes, client cannot perform its operation Support for multiple senders/receivers
E N D
Message Driven Beans Celsina Bignoli bignolic@smccd.net
Issues with RMI-IIOP • Performance • Client must wait for server response • Reliability • If server crashes, client cannot perform its operation • Support for multiple senders/receivers • RMI-IIOP support single client communicating to single server at any point in time
RMI-IIOP vs. Messaging • RMI • Messaging Application Application Application Application Application Application Application Message Middleware Application • receives messages from one or more • message producers • broadcasts these messages • to one or more message consumers
Enterprise Messaging Systems • a.k.a. : Message-oriented Middleware • facilitate the exchange of messages between software applications over a network. • Products • IBM's MQSeries • BEA's WebLogicJMS service • Sun Microsystems' Sun ONE Message Queue • Sonic's SonicMQ
Java Message Service (JMS) • provides vendor-independent access to enterprise messaging systems • consists of • API defining how to write code for receiving and sending messages • Service Provider Interface (SPI) to plug in JMS provider which knows how to talk to a specific MOM implementation
Definitions • JMS clients: applications that use JMS • JMS provider: the messaging system that handles routing and delivery of messages • JMS application: business system composed of many JMS clients and, generally, one JMS provider. • producer: JMS client that sends a message • Consumer:JMS client that receives a message. • A single JMS client can be both a producer and a consumer.
JMS Messaging Domains • Publish/subscribe (pub/sub) Producer1 Consumer1 Topic Producer2 Consumer2 • Point-to-point (PTP) Producer1 Queue Consumer1 Producer2
JMS Messaging Domains (2) • Publish/Subscribe • Many message producers communicate to many message consumers • Subscriber register interest into a particular event topic • Publishers create events for a topic • Publishers do not know who the consumers are, the MOM system maintains the subscriber list • Point-to-point • Single consumer for each message • Messages are sent to a queue • Queue can have multiple consumers but each message is consumed only once
JMS System JMS Driver Client Runtime 2: Create connection JMS Connection Factory JMS Server Queue 1 JMS Connection 3: Create session Queue 2 Topic 1 Serialized Message Comm. 5: Create consumer or producer Client JMS Session 1:Retrieve Connection Factory 4: Lookup JMS Destination JNDI JMS Producer Or JMS Consumer 6: Send or receive message
Message-driven Beans • Special EJB component invoked by the container upon arrival of a message at the destination or end point serviced by the message-driven bean • Completely decoupled from clients • A client cannot access a message-driven bean through any component interface • Client interact with a message-driven bean only through messages
Message-driven Beans Characteristics • does NOT have a home interface, local home interface, remote interface or local interface • Have weakly typed business methods • Listener methods might not have any return value • Might not send exceptions back to clients • Are stateless
Message-driven Beans Semantics • Class that implements the following interfaces: javax.jms.MessageListener javax.ejb.MessageDrivenBean • Must provide ejbCreate() method that takes no arguments and return void
Message-driven Beans Semantics(2) public interface javax.jms.MessageListener{ public void onMessage(Message message); } public interface javax.ejb.MessageDrivenBean extends javax.ejb.EnterpriseBean { public void ejbRemove() throws EJBException; public void setMessageDrivenContext (MessageDrivenContext ctx) throws EJBException; }
Message-driven bean Life Cycle does not exist 1: newInstance() 2: setMessageDrivenContextContext() 3: ejbCreate() ejbRemove() pooled onMessage()
Message-driven Beans caveats • Message Ordering • There is no guarantee that messages are delivered and processed in order • Missed ejbRemove() calls • This method ends up being used rarely, since message-driven been are usually only destroyed either at shutdown or when the EJB component is un-deployed