2. 总揽进入Message Service
3. 进入 Message Service
4. 分布式系统面临的问题、挑战异构系统集成（Heterogeneous Integration）
方案：FTP,Using the Database, Remote Procedure Call(RPC,HTTP,RMI-IIOP), Messaging, Web Services
Agility is the ability to respond quickly to a constantly changing environment.
5. 分布式系统目标 随着企业系统越来越复杂（complexity）和高精尖（sophistication），我们对系统提出了以下目标：
6. 分布式模型-RPC （Tightly Coupled）
7. 分布式模型-Enterprise Messaging
8. Enterprise MessagingMessage和Messaging的关系
A message is a self-contained package of business data and new routing headers.
The messaging by which messages are transmitted from one application to another across a network.
9. Messaging products也被称为MOM，Message-Oriented Middleware,消息中间件
商业产品：IBM WebSphere MQ , SonicMQ , Microsoft Message Queuing(MSMQ) and TIBCO Rendezvous , etc OpenSoure：Apache Active MQ（本文示例使用）, etc
10. Enterprise Messaging相关概念Web Services
ESB(Enterprise Service Bus)
11. Enterprise Messaging ArchitectursCentralized Architectures(hub and spoke)
14. Messaging的优点Asynchronous operation
A client can schedule work to be done and return
A client can be notified in an event-driven fashion
when something has happened
Systems connected via messaging need not be
aware of each other, or use the same technologies
Key messages can easily be routed to many systems
Message broker is buffer in case of downtime
15. Messaging的优点Fire and Forget
Message Broker can guarantee messages are
recorded and delivered even vs. crashes
Messages in a single stream can be handled in
parallel by many client threads or systems
A large amount of work can be split across a small
number of threads or systems to throttle effort (e.g.
due to licensing restrictions)
17. What is JMSThe Java API for messaging
Included in Java EE, available standalone
Key concepts include the message broker,message producers, message consumers, JMS topics vs. queues, and various message formats and processing options
Includes a plain Java API (a little complex); simplified in Java EE, Spring, etc.
− Those platforms simplify the process of establishing a connection to the message broker
18. What is JMSJMS本身不是消息系统，它只是消息客户端连接消息系统所使用的接口或类的抽象，类似JNDI提供对访问不同数据的抽象。通过JMS，客户端可以非常方便访问各种提供了JMS实现的消息系统。
最初，JMS主要提供访问企业消息系统的Java API，到JMS 1.2,已发展成为一流的Java 分布式计算模型，就像基于RPC的CORBA,EJB.
22. JMS APIJMS API可分成三类主要的API
23. JMS API 一览General APIP2P APIPub/Sub APIConnectionFactoryQueueConnectionFactoryTopicConnectionFactoryDestinationQueueTopicConnectionQueueConnectionTopicConnectionSessionQueueSessionTopicSessionMessageMessageMessageMessageProducerQueueSenderTopicPubliherMessageConsumerQueueReceiverTopicSubscriber
24. JMS General API core interface
26. JMS components
27. ConnectionFactory所有JMS核心组件中，ConnectionFactory和Destination必须通过JNDI从JMS Provider获取。
Is the base type for the TopicConnectionFactory and the QueueConnectionFactory
Be used to create a Connection object.
28. Destinationvirtual channels(called destinations)
In all modern enterprise messaging systems, applications exchange messages through virtual channels. When sending a message, the message is addressed to a destination, not a specific application. Any application that subscribes or registers an interest in that destination may receive that message.
Applications are decoupled.
Is the base interface for the Topic and Queue
29. ConnectionIs the base interface for the TopicConnection and the QueueConnection , and represents an open TCP/IP socket to the JMS provider.
30. SessionA single-threaded context for producing and consuming messages
Creates message consumers, producers, and messages for a specific JMS provider
Manages the scope of transactions across send and receive operations, tracks message acknowledgment for consumers, and serializes delivery of messages to MessageListener objects:
Is the base interface for the TopicSession and the QueueSession
31. Producers&ConsumnerMessageProducer sends messages to a specified destination (Topic or Queue)
Is the base interface for the TopicPublisher and the QueueSender.
32. Producers&ConsumnerMessageConsumer can consume messages asynchronously or synchronously
Is the base interface for the TopicSubscriber and the QueueReceiver.
33. MessageThe most important part of the entire JMS Spec.
All data and events in a JMS application are communicated with messages, while the rest of JMS exists to facilitate the transfer of messages
Messages are the lifeblood of the system
Has three parts: the message header, message properties, and finally the message data itself, called the payload or message body
34. Message-HeadersProvide metadata about the message describing who or what created the message, when it was created, how long the data is valid
Contain routing information
A lot more…
Divided into two large groups: automatically assigned headers and developer-assigned headers
37. Message-PropertiesAct like additional headers
Three basic categories of message properties: application-specific properties,JMS-defined properties, and provider-specific properties
38. Message结构-Message Type
39. Synchronous vs. AsynchronousProducers are effectively synchronous
Consumers may be synchronous or asynchronous:
− Sync: poll the broker for a new message, maybe with a timeout. Control returns when message available.
− Async: consumer provides a listener, and the listener is invoked when a new message is available
40. AsynchronousA fundamental concept of messaging is that communication between applications is intended to be asynchronous
Is the major difference between RPC and asynchronous messaging
Is critical to understanding the advantages offered by messaging systems.
41. MessageListenerReceives messages asynchronously from one or more Consumers (TopicSubscriber or QueueReceiver).
42. Delivery ModeTwo types of delivery modes in JMS: persistent and nonpersistent
Are used when establishing the delivery mode of a MessageProducer, TopicPublisher, or QueueSender
A persistent message should be delivered once-and-only-once
A nonpersistent message is delivered at-most-once
43. Other Key ConceptsMessage Selectors
45. Messaging Models-P2PPoint-to-Point(1-1)
46. P2P OutlineThe 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 to only one receiver
Messages are ordered
There is no coupling of the producers to the consumers
47. When to Use P2P MessagingIs used when you want one receiver to process any given message once and only once
Is used when you need synchronous communication between components, but those components are ritten in different programming languages or implemented in different technology platforms (e.g., J2EE and .NET)
is used when to provide a higher degree of throughput to server-side components through the use of message-based load balancing
52. Pub/Sub OutlineThe message producer is called a publisher and the message consumer a subscriber
Messages are exchanged through a virtual channel called a topic
Each message is delivered to multiple message consumers
The publisher generally does not know and is not aware of which subscribers are receiving the topic messages
Messages are pushed to consumers
53. Pub/Sub OutlineAs in enterprise messaging in general, there is no coupling of the producers to the consumers
Every client that subscribes to a topic receives its own copy of messages published to that topic
Message selectors are applied when the message is copied to each subscriber; whereas with the p2p model, message selectors are applied after the message has been added to the queue
Subscribers can be either durable or nondurable
Subscribers may also be dynamic or administered
54. When to Use Pub/Sub Messaging Is used when you want to broadcast a message or event to multiple message consumers
55. JMS Pub/Sub API core interface
56. Examplemortgage lender publishes mortgage rates and a borrower interested in the latest rates subscribes to the topic
59. Message FilteringTopic subscribers and queue receivers select what they want or interest. Filtering out certain messages from a queue and/or topic is done through message selectors.
Message selectors are based on a subset of the SQL-92 conditional expression syntax
Message selectors are made up of three elements: identifiers,literals, and comparison operators
60. Guaranteed MessagingGuaranteed messaging is the key to understanding the design of a distributed messaging system.
There are three main parts to guaranteed messaging
the underlying message acknowledgment semantics