600 likes | 753 Views
Using Message-Driven Beans in a Service-Oriented Architecture. Dave Chappell VP & Chief Technology Evangelist, Sonic Software. O’REILLY. Tell Them About the Book Raffle. Sonic Software. Driving Industry Standards. 1 st J2EE 1.3 Certified MOM! HTTP(S), XML, SOAP, WSDL, JMS, JCA
E N D
Using Message-Driven Beans in a Service-Oriented Architecture Dave Chappell VP & Chief Technology Evangelist, Sonic Software
Tell Them About the Book Raffle
Sonic Software Driving Industry Standards • 1st J2EE 1.3 Certified MOM! • HTTP(S), XML, SOAP, WSDL, JMS, JCA • Java Message Service (JMS) • Apache Axis • Web services, JAXM, J2EE CA • XML Schema • ebXML • WS-I
SonicMQ AppServer Integration • Borland Appserver • HP/Bluestone Total-e-server • BEA Weblogic • CMT,Clustering, Failover/Reconnect, Design Patterns • IBM WebSphere • Oracle Appserver • MacroMedia • JBoss (soon)
Sonic Software Recognized: Enterprise messagingIntegration middleware Established: Over 500 of Global 2000 rely on Sonic Software Strong Independent operating company of Progress Backing: Software Corp. (NASDAQ: PRGS) $170M cash, no debt Distribution in 65 countries, 24x7 world-wide support History: SonicMQ released 12/1999, #1 JMS product Today SonicMQ 4.0, SonicXQ 1.0 Enterprise Service Bus
Agenda • J2EE Message Driven Topology • JMS Overview • Using JMS With EJBs • JMS and XA Integration • J2EE Connector Architecture • Service Oriented Architectures and Web Services
J2EE Topology Internet Web Containers EJB Containers JSP html Database EJB EJB servlet xml EJB EJB xml JSP EJB EJB EIS servlet servlet EJB EJB gifs jpegs EJB Presentation Logic Business Logic
J2EE Topology – Message Driven EJBContainers EJBContainers EJB EJB MDB MDB MDB MDB EJB EJB MDB MDB EJB EJB Internet Web Containers Database JMS html JSP servlet servlet EIS gifs jpegs Presentation Logic Business Logic
J2EE Topology – Message Driven Head Office Business Partner EJB Server EJB Server EJB Server Broker EJB Server Broker EJB Server Trading Partner Regional Office Broker EJB Server Broker EJB Server EJB Server Business Partner
Agenda • J2EE Message Driven Topology • JMS Overview • Using JMS With EJBs • JMS and XA Integration • J2EE Connector Architecture • Service Oriented Architectures and Web Services
Java Message Service (JMS) • Sun standard • Common APIs • Loosely-coupled asynchronous processing • Senders and receivers abstractly decoupled from each other • Destinations administratively configurable at runtime • Point to Point and Pub/Sub messaging models • Supports synchronous or asynchronous communication
Java Message Service (JMS) • Message delivery semantics • Guaranteed Once-and-only-once • At-most-once • Deployment architecture not addressed by specification • Vendor differentiators
Java Message Service Messaging Components BusinessApplication A BusinessApplication A JMSProvider JMS Messaging API JMS Messaging API JMS Messaging Client JMS Messaging Client …standards based API…
Broad Range of Message Types MultiPartMessage Message BytesMessage MapMessage ObjectMessage StreamMessage TextMessage XMLMessage Included in JMS Specification Extensions in SonicMQ
JMS Messages Message Used to identify and route the message Header Properties Support application-specific values passed with the message Body The actual “payload” of the message (five different types, plus XML and Multipart for SonicMQ)
JMS Reliability 10. Receive 3. Send 1. Subscribe 6. Ack 8. Connect 9. Retrieve 4. Persist Persistent messages and durable subscriptions JMSProvider Publisher Subscriber 7. publish() method returns 2. Disconnect Persistent Store 5. Message retained in persistent store
JMS Reliability 6. commit() 4. Receive 1. Send 2. Send 5. Receive 3. commit() Transactional Message Send and Receive JMSProvider Producer Consumer
JMS Reliability 1. Send 2. Update XA Compliant Transaction Manager commit() JMSProvider Producer rollback() External Resource (DB/EJB)
Filtering with message selectors Publisher Departments.Sales JMSPriority = 2 Pipeline = 20000 not delivered Subscriber delivered Subscriber Message Server Departments.Sales Pipeline > 20000 Departments.Sales Pipeline > 15000 not delivered delivered Subscriber Subscriber Departments.Sales JMSPriority > 5 Departments.Sales JMSPriority >= 2 AND Pipeline > 10000
JMS as a J2EE Resource • 2 Requirements to access a Message Provider • ConnectionFactory • Creates connection to JMS providers • Destination Object • The Specific Topic or Queue
Obtaining the ConnectionFactory • Resource Manager Connection Factories as Administered Objects • Specify standard mechanism for getting connections to resources outside the J2EE component • Enables the container to do pooling • JNDI is used for maximum portability QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("java:comp/env/jms/TrafficConFactory");
Accessing the Destination • The Specific Queue or Topic • Retrieved via JNDI • Specified in the Deployment Descriptor • Binding to a real Destination done at deploy time Topic traffic = (Topic) ctx.lookup("java:comp/env/jms/TrafficTopic");
What the Java/API looks like // Create a connection factory TopicConnectionFactory factory; factory = (TopicConnectionFactory)jndi.lookup("TopicConnectionFactory"); // Create a connection connect = factory.createTopicConnection (username, password); // Create a session session = connect.createTopicSession(true, Session.AUTO_ACKNOWLEDGE); // Create a topics. Topic topic = (Topic)jndi.lookup("chat");
What the Java/API looks like // Create Subscriber to application topics. TopicSubscriber subscriber = session.createSubscriber(topic); // Initialize the onMessage() message handler. subscriber.setMessageListener(this); // Create a publisher publsher = session.createPublisher(null); // Topic will be set for each reply // Now setup is complete, start the Connection connect.start();
What the Java/API looks like public void onMessage( javax.jms.Message message){ TextMessage textMessage = (TextMessage) message; System.out.println(textMessage.getText()); } -- OR – ... while( true ){ textMessage = (javax.jms.TextMessage)qReceiver.receive(1000); ...
Do the Book Raffle
Agenda • J2EE Message Driven Topology • JMS Overview • Using JMS With EJBs • JMS and XA Integration • J2EE Connector Architecture • Service Oriented Architectures and Web Services
EJB Design Pattern Reminder Server provides resource mgmt create lookup remove home context create lookup remove client bean object methods methods Container Deployment Descriptor Automatically invokes services based on requirements defined in deployment descriptor Remote interface stubs
MessageDrivenBean EJB Container EJB Container PublisherBean SubscriberMsg-drivenInstance Delivers Publishes Acknowledges Stores DurableSubscription Database ClientApp
MessageDrivenBean • Defined in EJB 2.x Specification • Benefits • Simple to write • Allow for asynchronous execution JMS Provider Container Msg-driven Bean Class Msg-drivenBean instances Destination Consumer
MessageDrivenBean • Executes on receipt of a JMS message • javax.jms.MessageListener interface • Shares the following characteristics of stateless session bean • Is stateless and relatively short- lived • Security • Transactions • Concurrency • Management • All the other services that EJBs enjoy! • Notable difference: No home or remote interface
MessageDrivenBean Interface • javax.ejb.MessageDrivenBean • ejbCreate(), ejbRemove() • setMessageDrivenContext() • Just like a usual javax.jms.MessageListner • onMessage(javax.jms.Message)
MessageDrivenContext • get/setRollbackOnly() • getUserTransaction() • For BMT only • Others inherited from EJBContext Interface, but not allowed: • getCallerPrincipal() • isCallerInRole() • getEJBHome(), getEJBLocalHome()
Serialization and Concurrency • Container Must Serialize all calls to an MDB • ejbCreate(), ejbRemove(), etc • No need to be coded as re-entrant • Concurrency • Container May Launch Multiple Instances of an MDB • No guarantee of order • “Cancellation” Message May Arrive Before “Reservation” Message
MDB Example public class SubscriberMsgBean implements MessageDrivenBean { <… define ejbCreate(), ejbRemove() and setMessageDrivenContext( MessageDrivenContext mdc) .. > MessageDrivenContext mdc = null; public void onMessage( Message inMessage) { TextMessage msg = (TextMessage) inMessage; try { < look up JDBC database > < store info from message in database > } catch( Exception e) { mdc. setRollbackOnly(); } } }
MDB Example – Deployment Descriptors <message-driven> ... <ejb-class>SubscriberMsgBean</ejb-class> <transaction-type>Container</transaction-type> <jms-message-selector> NewsType='Metro/Region‘ </jms-message-selector> <message-driven-destination> <jms-destination-type> javax.jms.Topic </jms-destination-type> <jms-subscription-durability> durable </jms- subscription-durability> </message-driven-destination> ... </ message- driven>
Agenda • J2EE Message Driven Topology • JMS Overview • Using JMS With EJBs • JMS and XA Integration • J2EE Connector Architecture • Service Oriented Architectures and Web Services
Distributed Transaction Processing (DTP) TM TM TM XA XA XA XA XA XA XA XA XA RM RM RM RM RM RM RM RM RM XA TM RM XA XA RM RM RM TM RM RM
A local instance of a DTP system TM JMS Client RM RM
Local DTP zoom in EJB Application Server JMS Provider TransactionManager JMS XA API XA Resource SonicMQ Client JMS Client
XA interfaces • JMS XA SPI • XAConnectionFactory • XAConnection • XASession • XAQueueConnectionFactory • XAQueueConnection • XAQueueSession • XATopicConnectionFactory • XATopicConnection • XATopicSession
Agenda • J2EE Message Driven Topology • JMS Overview • Using JMS With EJBs • JMS and XA Integration • J2EE Connector Architecture • Service Oriented Architectures and Web Services
J2EE 1.3 Web Applications Asynchronous JMS MDB EJB 2.0 J2EE 1.4 SOA Platform Web Services JAX-RPC JSR-109 J2EE Connector Architecture EJB 2.1 WSEI J2EE Directions
J2EE Connector Architecture Overview Application Server or EAI Framework System Contract Resource Adapter EIS Interface Enterprise Information System • Defines standard for connecting J2EE to enterprise information systems (EIS) • System contracts define interface specification with EIS • Connection, Transaction, Security
J2EE Connector Architecture Overview Application Server or EAI Framework System Contract Resource Adapter EIS Interface Enterprise Information System • Resource adapters • Implements the EIS side of the system contracts • System-level software drivers for connecting to an EIS • Enables vendors to create standardized connectors to EIS • Common client interface • Standard API for applications to interact with heterogeneous EIS
Inbound Communication Model JCA Container WorkManager Connection PoolManager TransactionManager SecurityManager ResourceAdapter JMS Destination WorkMgmt JMSDisp EnterpriseJavaBeans EJBDisp