JMS结构模型
1.ConnectionFactory
A ConnectionFactory
object encapsulates a set of connection configuration parameters that has been defined by an administrator. A client uses it to create a connection with a JMS provider.
A ConnectionFactory
object is a JMS administered object and supports concurrent use.
JMS administered objects are objects containing configuration information that are created by an administrator and later used by JMS clients. They make it practical to administer the JMS API in the enterprise.
Although the interfaces for administered objects do not explicitly depend on the Java Naming and Directory Interface (JNDI) API, the JMS API establishes the convention that JMS clients find administered objects by looking them up in a JNDI namespace.
An administrator can place an administered object anywhere in a namespace. The JMS API does not define a naming policy.
It is expected that JMS providers will provide the tools an administrator needs to create and configure administered objects in a JNDI namespace. JMS provider implementations of administered objects should be both javax.jndi.Referenceable
and java.io.Serializable
so that they can be stored in all JNDI naming contexts. In addition, it is recommended that these implementations follow the JavaBeansTM design patterns.
This strategy provides several benefits:
- It hides provider-specific details from JMS clients.
- It abstracts administrative information into objects in the Java programming language ("Java objects") that are easily organized and administered from a common management console.
- Since there will be JNDI providers for all popular naming services, this means that JMS providers can deliver one implementation of administered objects that will run everywhere.
An administered object should not hold on to any remote resources. Its lookup should not use remote resources other than those used by the JNDI API itself.
Clients should think of administered objects as local Java objects. Looking them up should not have any hidden side effects or use surprising amounts of local resources.
2.Connection
A Connection
object is a client's active connection to its JMS provider. It typically allocates provider resources outside the Java virtual machine (JVM).
Connections support concurrent use.
A connection serves several purposes:
- It encapsulates an open connection with a JMS provider. It typically represents an open TCP/IP socket between a client and the service provider software.
- Its creation is where client authentication takes place.
- It can specify a unique client identifier.
- It provides a
ConnectionMetaData
object. - It supports an optional
ExceptionListener
object.
Because the creation of a connection involves setting up authentication and communication, a connection is a relatively heavyweight object. Most clients will do all their messaging with a single connection. Other more advanced applications may use several connections. The JMS API does not architect a reason for using multiple connections; however, there may be operational reasons for doing so.
A JMS client typically creates a connection, one or more sessions, and a number of message producers and consumers. When a connection is created, it is in stopped mode. That means that no messages are being delivered.
It is typical to leave the connection in stopped mode until setup is complete (that is, until all message consumers have been created). At that point, the client calls the connection's start
method, and messages begin arriving at the connection's consumers. This setup convention minimizes any client confusion that may result from asynchronous message delivery while the client is still in the process of setting itself up.
A connection can be started immediately, and the setup can be done afterwards. Clients that do this must be prepared to handle asynchronous message delivery while they are still in the process of setting up.
A message producer can send messages while a connection is stopped.
From :java api
3.Session
public interface Sessionextends java.lang.Runnable
A Session
object is a single-threaded (单线程)context for producing and consuming messages. Although it may allocate provider resources outside the Java virtual machine (JVM), it is considered a lightweight JMS object.
A session serves several purposes:
- It is a factory for its message producers and consumers.
- It supplies provider-optimized message factories.
- It is a factory for
TemporaryTopics
andTemporaryQueues
. - It provides a way to create
Queue
orTopic
objects for those clients that need to dynamically manipulate provider-specific destination names. - It supports a single series of transactions that combine work spanning its producers and consumers into atomic units.
- It defines a serial order for the messages it consumes and the messages it produces.
- It retains messages it consumes until they have been acknowledged.
- It serializes execution of message listeners registered with its message consumers.
- It is a factory for
QueueBrowsers
.
A session can create and service multiple message producers and consumers.
One typical use is to have a thread block on a synchronous MessageConsumer
until a message arrives. The thread may then use one or more of the Session
's MessageProducer
s.
If a client desires to have one thread produce messages while others consume them, the client should use a separate session for its producing thread.
Once a connection has been started, any session with one or more registered message listeners is dedicated to the thread of control that delivers messages to it. It is erroneous for client code to use this session or any of its constituent objects from another thread of control. The only exception to this rule is the use of the session or connection close
method.
It should be easy for most clients to partition their work naturally into sessions. This model allows clients to start simply and incrementally add message processing complexity as their need for concurrency grows.
The close
method is the only session method that can be called while some other session method is being executed in another thread.
A session may be specified as transacted. Each transacted session supports a single series of transactions. Each transaction groups a set of message sends and a set of message receives into an atomic unit of work. In effect, transactions organize a session's input message stream and output message stream into series of atomic units. When a transaction commits, its atomic unit of input is acknowledged and its associated atomic unit of output is sent. If a transaction rollback is done, the transaction's sent messages are destroyed and the session's input is automatically recovered.
The content of a transaction's input and output units is simply those messages that have been produced and consumed within the session's current transaction.
A transaction is completed using either its session's commit
method or its session's rollback
method. The completion of a session's current transaction automatically begins the next. The result is that a transacted session always has a current transaction within which its work is done.
The Java Transaction Service (JTS) or some other transaction monitor may be used to combine a session's transaction with transactions on other resources (databases, other JMS sessions, etc.). Since Java distributed transactions are controlled via the Java Transaction API (JTA), use of the session's commit
and rollback
methods in this context is prohibited.
The JMS API does not require support for JTA; however, it does define how a provider supplies this support.
Although it is also possible for a JMS client to handle distributed transactions directly, it is unlikely that many JMS clients will do this. Support for JTA in the JMS API is targeted at systems vendors who will be integrating the JMS API into their application server products.
表示一个单线程的上下文,用于发送和接收消息。由于会话是单线程的,所以消息是连续的,就是说消息是按照发送的顺序一个一个接收的。会话的好处是它支持事务。如果用户选择了事务支持,会话上下文将保存一组消息,直到事务被提交才发送这些消息。在提交事务之前,用户可以使用回滚操作取消这些消息。一个会话允许用户创建消息生产者来发送消息,创建消息消费者来接收消息。
4.MessageConsumer
A client uses a MessageConsumer
object to receive messages from a destination. A MessageConsumer
object is created by passing a Destination
object to a message-consumer creation method supplied by a session.
MessageConsumer
is the parent interface for all message consumers.
A message consumer can be created with a message selector. A message selector allows the client to restrict the messages delivered to the message consumer to those that match the selector.
A client may either synchronously receive a message consumer's messages or have the consumer asynchronously deliver them as they arrive.
For synchronous receipt, a client can request the next message from a message consumer using one of its receive
methods. There are several variations of receive
that allow a client to poll or wait for the next message.
For asynchronous delivery, a client can register a MessageListener
object with a message consumer. As messages arrive at the message consumer, it delivers them by calling the MessageListener
's onMessage
method.
It is a client programming error for a MessageListener
to throw an exception.
5.MessageProducer
A client uses a MessageProducer
object to send messages to a destination. A MessageProducer
object is created by passing a Destination
object to a message-producer creation method supplied by a session.
MessageProducer
is the parent interface for all message producers.
A client also has the option of creating a message producer without supplying a destination. In this case, a destination must be provided with every send operation. A typical use for this kind of message producer is to send replies to requests using the request's JMSReplyTo
destination.
A client can specify a default delivery mode, priority, and time to live for messages sent by a message producer. It can also specify the delivery mode, priority, and time to live for an individual message.
A client can specify a time-to-live value in milliseconds for each message it sends. This value defines a message expiration time that is the sum of the message's time-to-live and the GMT when it is sent (for transacted sends, this is the time the client sends the message, not the time the transaction is committed).
A JMS provider should do its best to expire messages accurately; however, the JMS API does not define the accuracy provided.
Including:QueueSender,TopicPublisher
6.Destination
A Destination
object encapsulates a provider-specific address. The JMS API does not define a standard address syntax. Although a standard address syntax was considered, it was decided that the differences in address semantics between existing message-oriented middleware (MOM) products were too wide to bridge with a single syntax.
Since Destination
is an administered object, it may contain provider-specific configuration information in addition to its address.
The JMS API also supports a client's use of provider-specific address names.
Destination
objects support concurrent use.
A Destination
object is a JMS administered object.
JMS administered objects are objects containing configuration information that are created by an administrator and later used by JMS clients. They make it practical to administer the JMS API in the enterprise.
Although the interfaces for administered objects do not explicitly depend on the Java Naming and Directory Interface (JNDI) API, the JMS API establishes the convention that JMS clients find administered objects by looking them up in a JNDI namespace.
An administrator can place an administered object anywhere in a namespace. The JMS API does not define a naming policy.
It is expected that JMS providers will provide the tools an administrator needs to create and configure administered objects in a JNDI namespace. JMS provider implementations of administered objects should implement the javax.naming.Referenceable
and java.io.Serializable
interfaces so that they can be stored in all JNDI naming contexts. In addition, it is recommended that these implementations follow the JavaBeansTM design patterns.
This strategy provides several benefits:
- It hides provider-specific details from JMS clients.
- It abstracts JMS administrative information into objects in the Java programming language ("Java objects") that are easily organized and administered from a common management console.
- Since there will be JNDI providers for all popular naming services, JMS providers can deliver one implementation of administered objects that will run everywhere.
An administered object should not hold on to any remote resources. Its lookup should not use remote resources other than those used by the JNDI API itself.
Clients should think of administered objects as local Java objects. Looking them up should not have any hidden side effects or use surprising amounts of local resources.
I will continue to learn about the detail about the difference between TOPIC and QUEUE, and the defination of the Message.
相关推荐
jms Javamessageservice结构图
消息可以是文本、二进制数据或者更复杂的数据结构。 2. **消息队列(Queue)** 和 **主题(Topic)**:是两种消息目的地类型。消息队列遵循“先进先出”(FIFO)原则,每个消息只有一个消费者;而主题支持发布/订阅...
消息可以是文本、二进制或其他复杂的数据结构。 2. **消息生产者(Message Producer)**:负责创建和发送消息到消息队列或主题的实体。生产者通过`Session`对象创建消息,并使用`MessageProducer`对象将其发送到...
3. 创建对应的目录结构,例如:`~/.m2/repository/jms/jms/1.1`。 4. 将下载的jar文件复制到新建的目录下,并创建一个名为`maven-metadata-local.xml`的元数据文件,里面包含版本信息。 5. 更新项目的pom.xml文件,...
- **消息队列**(Queue):FIFO(先进先出)结构,保证消息按顺序传递。 - **主题**(Topic):发布/订阅模型,多个订阅者可以接收相同的消息。 - **消息代理**(Message Broker)或**消息中间件**:处理消息路由...
- **消息服务体系结构**:JMS定义了两种主要的消息传送模型——点对点(Point-to-Point, PTP)和发布/订阅(Publish/Subscribe, Pub/Sub)模型。 - **消息传送模型对照表**:PTP模式使用Queue,消息只能被一个消费...
Spring-JMS是Spring框架的一部分,专门用于处理Java消息服务(JMS)的集成。它提供了一个简单的API,使得开发者能够方便地在应用中使用消息传递功能。本文将深入探讨Spring-JMS的基础知识,包括它的核心概念、配置...
根据企业应用程序间进行消息服务的实际需要,深入研究Java消息服务(Java Message Service,JMS)技术,结合其中的"发布/订阅式"和"点对点式"两种消息收发模式,提出了一个基于JMS体系结构的全新的消息服务模型,并针对股票...
XML常用于数据交换,因为它具有自我描述性和平台无关性,与JMS结合使用,可以使得消息的结构化和解析更为简单,从而在异构环境中实现文件的高效传输。 2. **JMS 使用 ActiveMQ 传送文件.doc** - 这个文档应该直接...
- **overview-tree.html**: 显示JMS API的类结构树,清晰展示类和接口的关系。 - **serialized-form.html**: 描述了可序列化的类及其序列化格式。 - **allclasses-frame.html**: 列出所有的类和接口,提供完整的...
另一个文件“layout.txt”可能包含固件布局信息,如硬件配置、分区结构等,用于指导固件安装或供开发者参考。 综上所述,这个压缩包文件提供的知识点主要包括: 1. USB3.0移动硬盘盒使用JMS578主控芯片,支持高速...
### JMS规范教程知识点解析 #### 一、JMS基本概念 **1.1 什么是JMS(JAVA MESSAGE SERVICE)?...JMS不仅提供了消息传递的基础结构,还涵盖了消息的管理和控制,使得开发者能够构建高效、可靠和灵活的企业级应用。
本文档旨在详细介绍JMS的基本结构、开发实例,帮助读者从入门到精通。 #### 二、JMS的基本结构 JMS提供了两个主要的消息域:点对点(PTP)和发布/订阅(Pub/Sub)。 1. **点对点(PTP)**:在此模式下,消息发送给特定的...
2.2 JMS结构图 JMS架构中,生产者通过JMeter发送消息到ActiveMQ,而消费者从队列或主题中接收消息。此测试涵盖了发布/订阅模型和点对点模型。 2.3 软硬件环境 硬件配置包括服务器的CPU、内存和磁盘性能,软件环境...
1. **消息**:JMS的核心是消息,它是一种数据结构,包含要传递的信息。消息可以是文本、二进制数据或者对象。 2. **消息队列(Message Queue)**:消息被发送到消息队列中,等待消费者进行处理。这种异步处理机制...
消息可以是文本、二进制数据或其他复杂结构,它们通过消息队列(Queue)或主题(Topic)进行传输。 1. **消息模型** - **点对点模型**:基于消息队列,每个消息只能被一个消费者接收,适合一对一的通信。 - **...
Java消息服务(Java Message Service,简称JMS)是Java平台中用于企业级应用集成的API,主要用于在分布式环境中传递消息,实现应用程序之间的异步通信。本教程将深入讲解JMS的核心概念、工作原理以及实际应用。 一...
2. **消息队列**:是一种先进先出(FIFO)的数据结构,每个消息只能被一个消费者消费一次。 3. **主题**:支持多播,允许多个订阅者接收同一消息,符合发布/订阅模式。 4. **生产者**:创建并发送消息的应用程序。 5...
1. **消息(Message)**:是JMS的核心,它是一个数据结构,用于封装要传递的信息。消息可以是文本、二进制数据或对象。 2. **消息队列(Message Queue)**:消息被发送到消息队列,然后由消费者从队列中取出。这种模式...