1 / 58

Using Message-Driven Beans in a Service-Oriented Architecture

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

zohar
Télécharger la présentation

Using Message-Driven Beans in a Service-Oriented Architecture

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using Message-Driven Beans in a Service-Oriented Architecture Dave Chappell VP & Chief Technology Evangelist, Sonic Software

  2. O’REILLY

  3. Tell Them About the Book Raffle

  4. 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

  5. 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)

  6. 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

  7. Agenda • J2EE Message Driven Topology • JMS Overview • Using JMS With EJBs • JMS and XA Integration • J2EE Connector Architecture • Service Oriented Architectures and Web Services

  8. 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

  9. 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

  10. 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

  11. Agenda • J2EE Message Driven Topology • JMS Overview • Using JMS With EJBs • JMS and XA Integration • J2EE Connector Architecture • Service Oriented Architectures and Web Services

  12. 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

  13. Java Message Service (JMS) • Message delivery semantics • Guaranteed Once-and-only-once • At-most-once • Deployment architecture not addressed by specification • Vendor differentiators

  14. 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…

  15. Broad Range of Message Types MultiPartMessage Message BytesMessage MapMessage ObjectMessage StreamMessage TextMessage XMLMessage Included in JMS Specification Extensions in SonicMQ

  16. 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)

  17. 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

  18. JMS Reliability 6. commit() 4. Receive 1. Send 2. Send 5. Receive 3. commit() Transactional Message Send and Receive JMSProvider Producer Consumer

  19. JMS Reliability 1. Send 2. Update XA Compliant Transaction Manager commit() JMSProvider Producer rollback() External Resource (DB/EJB)

  20. 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

  21. 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

  22. 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");

  23. 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");

  24. 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");

  25. 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();

  26. 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); ...

  27. Break

  28. Do the Book Raffle

  29. Agenda • J2EE Message Driven Topology • JMS Overview • Using JMS With EJBs • JMS and XA Integration • J2EE Connector Architecture • Service Oriented Architectures and Web Services

  30. 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

  31. MessageDrivenBean EJB Container EJB Container PublisherBean SubscriberMsg-drivenInstance Delivers Publishes Acknowledges Stores DurableSubscription Database ClientApp

  32. 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

  33. 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

  34. MessageDrivenBean Interface • javax.ejb.MessageDrivenBean • ejbCreate(), ejbRemove() • setMessageDrivenContext() • Just like a usual javax.jms.MessageListner • onMessage(javax.jms.Message)

  35. MessageDrivenContext • get/setRollbackOnly() • getUserTransaction() • For BMT only • Others inherited from EJBContext Interface, but not allowed: • getCallerPrincipal() • isCallerInRole() • getEJBHome(), getEJBLocalHome()

  36. 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

  37. 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(); } } }

  38. 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>

  39. Agenda • J2EE Message Driven Topology • JMS Overview • Using JMS With EJBs • JMS and XA Integration • J2EE Connector Architecture • Service Oriented Architectures and Web Services

  40. 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

  41. A local instance of a DTP system TM JMS Client RM RM

  42. Local DTP zoom in EJB Application Server JMS Provider TransactionManager JMS XA API XA Resource SonicMQ Client JMS Client

  43. XA interfaces • JMS XA SPI • XAConnectionFactory • XAConnection • XASession • XAQueueConnectionFactory • XAQueueConnection • XAQueueSession • XATopicConnectionFactory • XATopicConnection • XATopicSession

  44. Agenda • J2EE Message Driven Topology • JMS Overview • Using JMS With EJBs • JMS and XA Integration • J2EE Connector Architecture • Service Oriented Architectures and Web Services

  45. 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

  46. 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

  47. 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

  48. Inbound Communication Model JCA Container WorkManager Connection PoolManager TransactionManager SecurityManager ResourceAdapter JMS Destination WorkMgmt JMSDisp EnterpriseJavaBeans EJBDisp

More Related