Java message service

IBM: MQSeries Progress: SonicMQ Fiorano: FioranoMQ Softwired: iBus Sun Microsystems: Java Message Queue BEA: WebLogic Server ExoLab: OpenJMS

ppt85 trang | Chia sẻ: nguyenlam99 | Ngày: 05/01/2019 | Lượt xem: 50 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Java message service, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
Java Message ServicePresenter: Nguyễn Xuân VinhInformation Technology FacultyNong Lam University*Content Understanding The Messaging Paradigm1Concepts and Architecture of JMS2JMS Messaging Models3Anatomy of a JMS Message4JMS Features5JMS Providers6*Understanding The Messaging ParadigmSome concepts of messaging systemCentralized ArchitectureDecentralized Architecture*Some concepts of messaging systemMessaging systems allow different software applications to communicate with each other, generically referred to enterprise messaging systems, or Message-Oriented Middleware A key concept of enterprise messaging is messages are delivered asynchronously from one system to others over a network*Enterprise messaging systems allow two or more applications to exchange information in the form of messages A message is a self-contained package of business data and network routing headers In all modern enterprise messaging systems, applications exchange messages through virtual channels called destinations. Some concept of messaging system*In asynchronous messaging, applications use a simple API to construct a message, then hand it off to the Message-Oriented Middleware for delivery to one or more intended recipients. Some concept of messaging systemFigure 1.1. Message-Oriented Middleware *Some concept of messaging systemRPC vs Asynchronous MessagingRPC attempts to mimic the behavior of a system that runs in one process A failure on one system has an immediate and debilitating impact on other systems*RPC vs Asynchronous MessagingBusiness Application ARPC Client/ServerBusiness Application DRPC Client/ServerBusiness Application BRPC Client/ServerBusiness Application CRPC Client/ServerRequires n * (n-1) / 2 connectionsSome concept of messaging system*Some concept of messaging systemRPC vs Asynchronous MessagingA fundamental concept of MOM is that communication between applications is intended to be asynchronous In MOM, each subsystem is decoupled from the other systems *Some concept of messaging systemRPC vs Asynchronous MessagingCentralized message server (hub and spoke)JMS ClientMessage ServerJMS ClientJMS ClientJMS ClientJMS ClientJMS ClientJMS ClientLocal "server"JMS ClientLocal "server"JMS ClientLocal "server"JMS ClientApplication ALocal "server"Application BApplication CApplication DRouterDecentralized message server (IP multicast)*Centralized ArchitectureA message server is responsible for delivering messages from one messaging client to other messaging clientsThe message server decouples a sending client from other receiving clients *A centralized architecture uses a hub-and-spoke topology The hub-and-spoke architecture lends itself to a minimal amount of network connections while still allowing any part of the system to communicate with any other part of the system Centralized Architecture*Decentralized ArchitectureAll decentralized architectures currently use IP multicast at the network level Some of the server functionality (persistence, transactions, security) is embedded as a local part of the client, while message routing is delegated to the network layer by using the IP multicast protocol *IP multicast allows applications to join one or more IP multicast groups; each group uses an IP network address that will redistribute any messages it receives to all members in its group The network handles routing automatically Decentralized Architecture*ContentUnderstanding the Messaging Paradigm1Concepts and Architecture of JMS2JMS Messaging Models3Anatomy of a JMS Message4JMS Features5JMS Providers6*Concepts and Architecture of JMSWhat is JMS? Architecture of JMS*What is JMS?The JMS (Java Message Service) is an API for enterprise messaging created by Sun Microsystems JMS is not a messaging system itself JMS abstracts access to MOMs *Supports message production, distribution, deliverySupported message delivery semanticsSynchronous or AsynchronousTransactedGuaranteedDurableWhat is JMS?*Architecture of JMSJMS architectural componentsJMS clientsNon-JMS clientsMessagesJMS provider (Messaging systems)JNDI administered objectsDestinationConnectionFactory*Architecture of JMS applicationArchitecture of JMS*A JMS ApplicationJMS ClientsJava programs that send/receive messagesMessages Administered ObjectsPreconfigured JMS objects created by an admin for the use of clientsConnectionFactory, Destination (queue or topic)JMS ProviderMessaging system that implements JMS and administrative functionalityArchitecture of JMS*JMS AdministrationArchitecture of JMSAdministrativeToolJNDI NamespaceJMS ClientBindLookupLogicalConnectionJMS Provider*ContentUnderstanding the Messaging Paradigm1Concepts and Architecture of JMS2JMS Messaging Models3Anatomy of a JMS Message4JMS Features5JMS Providers6*JMS provides for two types of messaging models, publish-and-subscribe and point-to-point queuing JMS Messaging Models*Messaging clients in JMS are called JMS clients The messaging system - the MOM - is called the JMS provider A JMS application is a business system composed of many JMS clients and, generally, one JMS provider A JMS client that produces a message is called a producerA JMS client that receives a message is called a consumer JMS Messaging Models*JMS componentsJMS Messaging ModelsMessage ServerMessageMessageDestinationJMS ClientConnectionSessionProducerJMS ClientConnectionSessionConsumer*Connections and sessionsA connection connects to a message serverCan create one or more sessions within a connectionJMS ClientConnectionSessionSessionSessionJMS Messaging Models*Creating connections and sessionsMessage ServerJNDI StoreJMS ClientConnectionSessionSessionSessionConnectionFactorycreateConnectionFactoriesDestinationsJMS Messaging Models*JMS Messaging ModelsPublish-and-SubscribePoint-to-Point*Publish-and-SubscribeOne producer can send a message to many consumers through a virtual channel called a topic Consumers, which receive messages, can choose to subscribe to a topic Any messages addressed to a topic are delivered to all the topic's consumers Every consumer receives a copy of each message *Messages are automatically broadcast to consumers without them having to request or poll the topic for new messages Durable subscriptions allow consumers to disconnect, and later reconnect and collect messages that were published while they were disconnected Publish-and-Subscribe*Publish-and-SubscribePublisherTopicSubscriberSubscriberMSGMSGMSGSubscribe to a Topic*Publish-and-SubscribeJMS Pub-Sub Classes*Publish/Subscribe Applicationsubscribe (“AAPL”);subscribe (“SUN”);subscribe (“AAPL”);subscribe (“SUN”);publish (“AAPL”, 29.2);publish(“AAPL”, 29.3);publish (“SUN”, 43.0);publish(“SUN”, 42.7);Publish-and-Subscribe*Publish-and-SubscribePublish-and-Subscribe ExampleMessage ServerWholesalerRetailer 1Retailer 2Update price(publish)Order product(send)*Publish-and-SubscribePublish-and-Subscribe Example: WholesalerProperties env = new Properties();env.put("BROKER", broker);InitialContext jndi = new InitialContext(env);TopicConnectionFactory factory = (TopicConnectionFactory) jndi.lookup("TopicConnectionFactory");TopicConnection connect = factory.createTopicConnection(username, password);Topic hotDealsTopic = (Topic) jndi.lookup("Hot Deals");TopicPublisher publisher = pubSession.createPublisher(hotDealsTopic);*Publish-and-SubscribePublish-and-Subscribe Example: WholeSalerTopicSession pubSession = connect.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);TopicSession subSession = connect.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);TemporaryTopic buyOrdersTopic = subSession.createTemporaryTopic();TopicSubscriber subscriber = subSession.createSubscriber(buyOrdersTopic);*Publish-and-SubscribePublish-and-Subscribe Example: WholeSaler//Update price StreamMessage message = pubSession.createStreamMessage();message.writeString(dealDesc);message.setJMSReplyTo(buyOrdersTopic);publisher.publish(message, DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, 1800000);*Publish-and-SubscribePublish-and-Subscribe Example: WholeSalerpublic void onMessage(Message message) {try {TextMessage textMessage = (TextMessage) message;String text = textMessage.getText();.} catch (java.lang.Exception rte) { rte.printStackTrace();}}*Publish-and-SubscribePublish-and-Subscribe Example: RetailerTextMessage textMsg = session.createTextMessage();textMsg.setJMSCorrelationID("DurableRetailer");Topic buytopic = (Topic) message.getJMSReplyTo();publisher = session.createPublisher(buytopic);publisher.publish(textMsg, DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, 1800000);*Publish-and-SubscribePublish-and-Subscribe Example Demo*Publish-and-SubscribePublish-and-Subscribe Example: ChatTopicMSGMSGMSGMSG*Point-to-PointIn the p2p model, the producer is called a sender and the consumer is called a receiver Messages are exchanged through a virtual channel called a queue Each message is delivered only to one receiver *Messages are orderedQueue can have multiple consumers but each message is consumed only onceThere is no coupling of the producers to the consumersPoint-to-Point*P2P messages are always delivered, regardless of receiver connection stateP2P Queue can push or pull messages with regard to the receiveronMessage() – callback, asyncreceive() – method, syncPoint-to-Point*Point-to-PointSenderQueuePotentialReceiverPotentialReceiverMSGMSGConsumes messageQueuePotentialReceiverPotentialReceiverQueuePotentialReceiver*Browsing a queuenextElement();QueueBrowsergetEnumeration();Message1Message2Message3Message4EnumerationPoint-to-Point*Message Queuing ApplicationPoint-to-Point*P2P and Pub/SubBased on the concept of sending a message to a named destination There is no direct coupling of the producers to the consumers The pub/sub model is based on a push model. While a p2p queue can either push or pull messages*In the pub/sub model, multiple consumers that subscribe to the same topic each receive their own copy of every message addressed to that topicIn the p2p model, multiple consumers can use the same queue, but each message delivered to the queue can only be received by one of the queue's consumers P2P and Pub/Sub*JMS API Programming ModelConnectioncreatescreatescreatesMsgDestinationreceives fromsends toConnectionFactoryDestinationMessageConsumerSessionMessageProducercreates*ContentUnderstanding the Messaging Paradigm1Concepts and Architecture of JMS2JMS Messaging Models3Anatomy of a JMS Message4JMS Features5JMS Providers6*The Message is the most important part of the entire JMS specification A JMS message both carries application data and provides event notification Anatomy of a JMS Message*PayloadHeaderPropertiesAnatomy of a JMS Message*Used for identifying and routing messagesTypically name/value pairsJMS headers are divided into two large groupsAutomatically assigned headersDeveloper assigned headersHeaders*HeadersAutomatically assigned headersJMSDestinationJMSDeliveryModeJMSMessageIDJMSTimestampJMSExpirationJMSRedeliveredJMSPriorityDeveloper-assigned headersJMSReplyToJMSCorrelationIDJMSType*PropertiesAct like additional headers that can be assigned to a message Provide the developer with more information about the message There are three basic categories of message properties Application-specific propertiesJMS-defined propertiesProvider-specific properties *Message TypesMessage typeMessage bodyMessageNo body TextMessageA standard Java stringObjectMessageA serializable Java objectMapMessageA set of name/value pairs where values are Java primitivesStreamMessageA stream of Java primitivesBytesMessageA stream of uninterpreted bytes*When messages are delivered, the body and properties of the message is made read-only Message Types*Message SelectorsAllows a JMS consumer to be more selective about the messages it receives from a particular destination Use message properties and headers as criteria in conditional expressions Based on a subset of the SQL-92 conditional expression syntax *Example of Message SelectorAge = 100.00 AND LName = 'Smith' Identifiers Literals Comparison OperatorsMessage Selectors*ContentUnderstanding the Messaging Paradigm1Concepts and Architecture of JMS2JMS Messaging Models3Anatomy of a JMS Message4JMS Features5JMS Providers6*JMS FeaturesGuaranteed MessagingTransactionsAcknowledgments and Failures*There are three main parts to guaranteed messaging Message autonomyStore-and-forwardMessage acknowledgmentGuaranteed Messaging*Message autonomyMessages are self-contained autonomous entities Guaranteed Messaging*Store-and-forwardWhen messages are marked persistent, it is the responsibility of the JMS provider to utilize a store-and-forward mechanism to fulfill its contract with the sender Guaranteed Messaging*Message acknowledgmentA key part of guaranteed messaging Servers acknowledge the receipt of messages from JMS producers JMS consumers acknowledge the receipt of messages from servers Guaranteed Messaging*Acknowledgment ModesAUTO ACKNOWLEDGECLIENT ACKNOWLEDGEDUPS OK ACKNOWLEDGEGuaranteed Messaging*Acknowledge ModesAUTO ACKNOWLEDGESession automatically acknowledges a client’s receipt of a messageReturns from a call to receive or the MessageListener it has called to process the message successfullyGuaranteed Messaging*Acknowledge ModesAUTO ACKNOWLEDGECLIENT ACKNOWLEDGEClient acknowledges a message by calling the message’s acknowledge methodAcknowledging a consumed message automatically acknowledges the receipt of all messages that have been delivered by the sessionGuaranteed Messaging*Acknowledge ModesAUTO ACKNOWLEDGECLIENT ACKNOWLEDGEDUPS OK ACKNOWLEDGELazily acknowledge the delivery of messagesCan cause duplicated messagesWe handle the same way as AUTO ACKNOWLEDGEGuaranteed Messaging*TransactionsTransacted Session: ProducerJMS provider will not start delivery of the messages to its consumers until the producer has issued a commit( ) on the session*Transacted Session: ProducerProducerMessage ServerConsumerBefore commit( )Upon commit( )Message ServerTransacted sessionTransactions*Transacted Session: ConsumerJMS provider hold messages delivered until the receiver issues a commit( ) on the session object Transactions*Transacted Session: ConsumerTransactionsMessage ServerConsumerBefore commit( )Upon commit( )Message ServerConsumer12Deliver messagesConsume messages12Acknowledge messagesDelete messages if all recipients have acknowledged*Distributed TransactionsMessage ServerJNDI StoreJMS ClientXAConnectionXASessionXASessionXASessionXAConnectionFactorycreateConnectionFactoriesDestinationsTransactions*Lost connectionWhen a network connection between the client and server is lost, a JMS provider must make every reasonable attempt to re-establish the connection Acknowledgments and Failures*Recovering from a lost connectionClient runtimeMessage ServerExceptionListeneronException()ReconnectAcknowledgments and Failures*JMS with EJBMessage–Driven BeanActs as a listener for the JMS, processing messages asynchronouslySpecialized adaptation of the JMS API used in the context of J2EE applications*JMS with EJBMessage-driven bean Life Cycledoes not existpooled1: newInstance()2: setMessageDrivenContextContext()3: ejbCreate()ejbRemove()onMessage()*JMS with EJBJMS with EJB Example*JMS with EJBEJB is a server-side component that encapsulates the business logic of an applicationEJB simplifies the development of large, distributed applicationsEJB Container provides system-level servicese.g. transaction management, authorizationBeans have the control logicthin client applicationsPortable componentscan run on any compliant J2EE server*ContentUnderstanding the Messaging Paradigm1Concepts and Architecture of JMS2JMS Messaging Models3Anatomy of a JMS Message4JMS Features5JMS Providers6*JMS ProvidersIBM: MQSeriesProgress: SonicMQ Fiorano: FioranoMQ Softwired: iBus Sun Microsystems: Java Message Queue BEA: WebLogic Server ExoLab: OpenJMS HỎI ĐÁP

Các file đính kèm theo tài liệu này:

  • pptch09_javamessageservice_8897.ppt
Tài liệu liên quan