|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.jms Interface Session
- All Superinterfaces:
- Runnable
- All Known Subinterfaces:
- QueueSession, TopicSession, XAQueueSession, XASession, XATopicSession
public interface Session
- extends Runnable
Session
对象是生产和使用消息的单线程上下文。尽管它可以在 Java 虚拟机 (JVM) 外部分配提供者资源,但它仍被认为是一个轻量级 JMS 对象。
会话有几个用途:
- 它是其消息生成方和使用方的工厂。
- 它提供提供者最优化的消息工厂。
- 它是
TemporaryTopics
和TemporaryQueues
的工厂。 - 它为需要动态操作特定于提供者的目的地名称的那些客户端提供创建
Queue
或Topic
对象的方法。 - 它支持一组事务将跨生成方和使用方的工作组合成原子单元。
- 它为自己使用的消息和生产的消息定义串行顺序。
- 它保留自己使用的消息,直到这些消息得到确认为止。
- 它序列化向其消息使用方注册的消息侦听器的执行。
- 它是
QueueBrowsers
的工厂。
一个会话可以创建并服务于多个消息生成方和使用方。
一个通常的用途是在同步的 MessageConsumer
上存在线程阻塞,直到消息到达。然后,该线程可以使用 Session
的一个或多个 MessageProducer
。
如果客户端希望一个线程生产消息,而其他线程使用消息,则客户端应为其生产线程使用单独的会话。
在启动连接后,任何具有一个或多个已注册消息侦听器的会话都专门用于将消息传送给它的控制线程。客户端代码在其他控制线程中使用此会话或其任何组成对象都是错误的。此规则的唯一例外是使用会话或连接 close
方法。
大多数客户端应该可以轻松地将其工作自然划分到会话中。此模型使客户端可以轻松启动,并随着它们并发需要的增加逐步增加消息处理复杂性。
close
方法是在其他线程中正在执行其他某个会话方法时可以调用的唯一会话方法。
可以将会话指定为事务性的。每个事务性会话都支持一组事务。每个事务都将一组发送的消息和一组接收的消息分组成一个工作的原子单元。实际上,事务将会话的输入消息流和输出消息流组织成一系列原子单元。当事务提交时,其输入原子单元会得到确认,而其相关的输出原子单元会被发送。如果发生事务回滚,则该事务发送的消息会被销毁,而会话的输入会自动恢复。
事务输入和输出单元的内容只是那些在该会话当前事务内已生产和使用的消息。
使用其会话的 commit
方法或其会话的 rollback
方法来完成事务。完成会话的当前事务后,会自动开始下一个事务。因此,事务性会话始终有一个在其中执行工作的当前事务。
Java Transaction Service (JTS) 或其他某个事务监视器可用于将会话的事务与其他资源(数据库、其他 JMS 会话等)上的事务相结合。因为 Java 分布式事务是通过 Java Transaction API (JTA) 控制的,所以禁止在此上下文中使用会话的 commit
和 rollback
方法。
JMS API 不要求支持 JTA;但是,它确实定义了提供者提供此支持的方式。
尽管 JMS 客户端也可以直接处理分布式事务,但不太可能有很多 JMS 客户端会这样做。 在 JMS API 中对 JTA 的支持是为要将 JMS API 集成到其应用服务器产品的系统供应商准备的。
version |
| |
See also | javax.jms.QueueSession, javax.jms.TopicSession, javax.jms.XASession |
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.
- Version:
- 1.1 February 2, 2002
- Author:
- Mark Hapner, Rich Burridge, Kate Stout
- See Also:
QueueSession
,TopicSession
,XASession
Field Summary | |
---|---|
static int |
AUTO_ACKNOWLEDGE
With this acknowledgment mode, the session automatically acknowledges a client's receipt of a message either when the session has successfully returned from a call to receive or when the message
listener the session has called to process the message successfully
returns. |
static int |
CLIENT_ACKNOWLEDGE
With this acknowledgment mode, the client acknowledges a consumed message by calling the message's acknowledge method. |
static int |
DUPS_OK_ACKNOWLEDGE
This acknowledgment mode instructs the session to lazily acknowledge the delivery of messages. |
static int |
SESSION_TRANSACTED
This value is returned from the method getAcknowledgeMode if the session is transacted. |
Method Summary | |
---|---|
void |
close()
Closes the session. |
void |
commit()
Commits all messages done in this transaction and releases any locks currently held. |
QueueBrowser |
createBrowser(Queue queue)
Creates a QueueBrowser object to peek at the messages on
the specified queue. |
QueueBrowser |
createBrowser(Queue queue,
String messageSelector)
Creates a QueueBrowser object to peek at the messages on
the specified queue using a message selector. |
BytesMessage |
createBytesMessage()
Creates a BytesMessage object. |
MessageConsumer |
createConsumer(Destination destination)
Creates a MessageConsumer for the specified destination. |
MessageConsumer |
createConsumer(Destination destination,
String messageSelector)
Creates a MessageConsumer for the specified destination,
using a message selector. |
MessageConsumer |
createConsumer(Destination destination,
String messageSelector,
boolean NoLocal)
Creates MessageConsumer for the specified destination, using a
message selector. |
TopicSubscriber |
createDurableSubscriber(Topic topic,
String name)
Creates a durable subscriber to the specified topic. |
TopicSubscriber |
createDurableSubscriber(Topic topic,
String name,
String messageSelector,
boolean noLocal)
Creates a durable subscriber to the specified topic, using a message selector and specifying whether messages published by its own connection should be delivered to it. |
MapMessage |
createMapMessage()
Creates a MapMessage object. |
Message |
createMessage()
Creates a Message object. |
ObjectMessage |
createObjectMessage()
Creates an ObjectMessage object. |
ObjectMessage |
createObjectMessage(Serializable object)
Creates an initialized ObjectMessage object. |
MessageProducer |
createProducer(Destination destination)
Creates a MessageProducer to send messages to the specified
destination. |
Queue |
createQueue(String queueName)
Creates a queue identity given a Queue name. |
StreamMessage |
createStreamMessage()
Creates a StreamMessage object. |
TemporaryQueue |
createTemporaryQueue()
Creates a TemporaryQueue object. |
TemporaryTopic |
createTemporaryTopic()
Creates a TemporaryTopic object. |
TextMessage |
createTextMessage()
Creates a TextMessage object. |
TextMessage |
createTextMessage(String text)
Creates an initialized TextMessage object. |
Topic |
createTopic(String topicName)
Creates a topic identity given a Topic name. |
int |
getAcknowledgeMode()
Returns the acknowledgement mode of the session. |
MessageListener |
getMessageListener()
Returns the session's distinguished message listener (optional). |
boolean |
getTransacted()
Indicates whether the session is in transacted mode. |
void |
recover()
Stops message delivery in this session, and restarts message delivery with the oldest unacknowledged message. |
void |
rollback()
Rolls back any messages done in this transaction and releases any locks currently held. |
void |
run()
Optional operation, intended to be used only by Application Servers, not by ordinary JMS clients. |
void |
setMessageListener(MessageListener listener)
Sets the session's distinguished message listener (optional). |
void |
unsubscribe(String name)
Unsubscribes a durable subscription that has been created by a client. |
Field Detail |
---|
英文文档:
AUTO_ACKNOWLEDGE
static final int AUTO_ACKNOWLEDGE
- With this acknowledgment mode, the session automatically acknowledges
a client's receipt of a message either when the session has successfully
returned from a call to
receive
or when the message listener the session has called to process the message successfully returns.- See Also:
- Constant Field Values
英文文档:
CLIENT_ACKNOWLEDGE
static final int CLIENT_ACKNOWLEDGE
- With this acknowledgment mode, the client acknowledges a consumed
message by calling the message's
acknowledge
method. Acknowledging a consumed message acknowledges all messages that the session has consumed.When client acknowledgment mode is used, a client may build up a large number of unacknowledged messages while attempting to process them. A JMS provider should provide administrators with a way to limit client overrun so that clients are not driven to resource exhaustion and ensuing failure when some resource they are using is temporarily blocked.
- See Also:
Message.acknowledge()
, Constant Field Values
英文文档:
DUPS_OK_ACKNOWLEDGE
static final int DUPS_OK_ACKNOWLEDGE
- This acknowledgment mode instructs the session to lazily acknowledge
the delivery of messages. This is likely to result in the delivery of
some duplicate messages if the JMS provider fails, so it should only be
used by consumers that can tolerate duplicate messages. Use of this
mode can reduce session overhead by minimizing the work the
session does to prevent duplicates.
- See Also:
- Constant Field Values
英文文档:
SESSION_TRANSACTED
static final int SESSION_TRANSACTED
- This value is returned from the method
getAcknowledgeMode
if the session is transacted. If aSession
is transacted, the acknowledgement mode is ignored.- See Also:
- Constant Field Values
Method Detail |
---|
public BytesMessage
createBytesMessage() throws JMSException
创建 BytesMessage
对象。BytesMessage
对象用于发送包含未解释字节流的消息。
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法创建此消息。 |
createBytesMessage
BytesMessage createBytesMessage() throws JMSException
- Creates a
BytesMessage
object. ABytesMessage
object is used to send a message containing a stream of uninterpreted bytes. - Throws:
JMSException
- if the JMS provider fails to create this message due to some internal error.
public MapMessage
createMapMessage() throws JMSException
创建 MapMessage
对象。MapMessage
对象用于发送一组自定义的名称-值对,其中名称是 String
对象,而值是 Java 编程语言中的原始值。
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法创建此消息。 |
createMapMessage
MapMessage createMapMessage() throws JMSException
- Creates a
MapMessage
object. AMapMessage
object is used to send a self-defining set of name-value pairs, where names areString
objects and values are primitive values in the Java programming language. - Throws:
JMSException
- if the JMS provider fails to create this message due to some internal error.
public Message
createMessage() throws JMSException
创建 Message
对象。Message
接口是所有 JMS 消息的根接口。
Message
对象保留所有标准消息头信息。如果仅包含头信息的消息便已足够,则可以发送该对象。
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法创建此消息。 |
createMessage
Message createMessage() throws JMSException
- Creates a
Message
object. TheMessage
interface is the root interface of all JMS messages. AMessage
object holds all the standard message header information. It can be sent when a message containing only header information is sufficient. - Throws:
JMSException
- if the JMS provider fails to create this message due to some internal error.
public ObjectMessage
createObjectMessage() throws JMSException
创建 ObjectMessage
对象。
ObjectMessage
对象用于发送包含可序列化 Java 对象的消息。
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法创建此消息。 |
createObjectMessage
ObjectMessage createObjectMessage() throws JMSException
- Creates an
ObjectMessage
object. AnObjectMessage
object is used to send a message that contains a serializable Java object. - Throws:
JMSException
- if the JMS provider fails to create this message due to some internal error.
public ObjectMessage
createObjectMessage(java.io.Serializable object) throws JMSException
创建已初始化的 ObjectMessage
对象。
ObjectMessage
对象用于发送包含可序列化 Java 对象的消息。
object | 要用于初始化此消息的对象 |
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法创建此消息。 |
createObjectMessage
ObjectMessage createObjectMessage(Serializable object) throws JMSException
- Creates an initialized
ObjectMessage
object. AnObjectMessage
object is used to send a message that contains a serializable Java object. - Parameters:
object
- the object to use to initialize this message- Throws:
JMSException
- if the JMS provider fails to create this message due to some internal error.
public StreamMessage
createStreamMessage() throws JMSException
创建 StreamMessage
对象。
StreamMessage
对象用于发送 Java 编程语言中自定义的原始值的流。
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法创建此消息。 |
createStreamMessage
StreamMessage createStreamMessage() throws JMSException
- Creates a
StreamMessage
object. AStreamMessage
object is used to send a self-defining stream of primitive values in the Java programming language. - Throws:
JMSException
- if the JMS provider fails to create this message due to some internal error.
public TextMessage
createTextMessage() throws JMSException
创建 TextMessage
对象。TextMessage
对象用于发送包含 String
对象的消息。
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法创建此消息。 |
createTextMessage
TextMessage createTextMessage() throws JMSException
- Creates a
TextMessage
object. ATextMessage
object is used to send a message containing aString
object. - Throws:
JMSException
- if the JMS provider fails to create this message due to some internal error.
public TextMessage
createTextMessage(String text) throws JMSException
创建已初始化的 TextMessage
对象。
TextMessage
对象用于发送包含 String
的消息。
text | 用于初始化此消息的字符串 |
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法创建此消息。 |
createTextMessage
TextMessage createTextMessage(String text) throws JMSException
- Creates an initialized
TextMessage
object. ATextMessage
object is used to send a message containing aString
. - Parameters:
text
- the string used to initialize this message- Throws:
JMSException
- if the JMS provider fails to create this message due to some internal error.
public boolean
getTransacted() throws JMSException
指示会话是否处于事务性模式。
return | true 如果会话处于事务性模式 |
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法返回事务模式。 |
getTransacted
boolean getTransacted() throws JMSException
- Indicates whether the session is in transacted mode.
- Returns:
- true if the session is in transacted mode
- Throws:
JMSException
- if the JMS provider fails to return the transaction mode due to some internal error.
public int
getAcknowledgeMode() throws JMSException
返回会话的确认模式。确认模式在创建会话时设置。如果会话是事务性的,则忽略确认模式。
return | 如果会话不是事务性的,则返回该会话的当前确认模式。如果会话是事务性的,则返回 SESSION_TRANSACTED。 |
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法返回确认模式。 |
since | 1.1 |
See also | createSession |
getAcknowledgeMode
int getAcknowledgeMode() throws JMSException
- Returns the acknowledgement mode of the session. The acknowledgement
mode is set at the time that the session is created. If the session is
transacted, the acknowledgement mode is ignored.
- Returns:
- If the session is not transacted, returns the current acknowledgement mode for the session. If the session is transacted, returns SESSION_TRANSACTED.
- Throws:
JMSException
- if the JMS provider fails to return the acknowledgment mode due to some internal error.- Since:
- 1.1
- See Also:
Connection.createSession(boolean, int)
public void
commit() throws JMSException
提交此事务中执行的所有消息,并释放当前保持的所有锁。
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法提交事务。 |
Throws | TransactionRolledBackException: 如果在提交过程中,事务由于某个内部错误回滚。 |
Throws | IllegalStateException: 如果该方法未由事务性会话调用。 |
commit
void commit() throws JMSException
- Commits all messages done in this transaction and releases any locks
currently held.
- Throws:
JMSException
- if the JMS provider fails to commit the transaction due to some internal error.TransactionRolledBackException
- if the transaction is rolled back due to some internal error during commit.IllegalStateException
- if the method is not called by a transacted session.
public void
rollback() throws JMSException
回滚此事务中执行的任何消息,并释放当前保持的所有锁。
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法回滚事务。 |
Throws | IllegalStateException: 如果该方法未由事务性会话调用。 |
rollback
void rollback() throws JMSException
- Rolls back any messages done in this transaction and releases any locks
currently held.
- Throws:
JMSException
- if the JMS provider fails to roll back the transaction due to some internal error.IllegalStateException
- if the method is not called by a transacted session.
public void
close() throws JMSException
关闭会话。
由于提供者可能会代表会话分配 JVM 之外的某些资源,因此不需要这些资源时客户端应该关闭它们。 依赖于垃圾收集最终回收这些资源可能不够及时。
无需关闭已关闭会话的生成方和使用方。
此调用将会一直阻塞,直到正在执行的 receive
调用或消息侦听器完成为止。当此会话关闭时,已阻塞的消息使用方 receive
调用返回 null
。
关闭事务性会话必定回滚正在执行的事务。
此方法是唯一可并发调用的 Session
方法。
对已关闭会话调用任何其他 Session
方法必定抛出 JMSException.IllegalStateException
。关闭已关闭的会话不会抛出异常。
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法关闭此会话。 |
close
void close() throws JMSException
- Closes the session.
Since a provider may allocate some resources on behalf of a session outside the JVM, clients should close the resources when they are not needed. Relying on garbage collection to eventually reclaim these resources may not be timely enough.
There is no need to close the producers and consumers of a closed session.
This call will block until a
receive
call or message listener in progress has completed. A blocked message consumerreceive
call returnsnull
when this session is closed.Closing a transacted session must roll back the transaction in progress.
This method is the only
Session
method that can be called concurrently.Invoking any other
Session
method on a closed session must throw aJMSException.IllegalStateException
. Closing a closed session must not throw an exception. - Throws:
JMSException
- if the JMS provider fails to close the session due to some internal error.
public void
recover() throws JMSException
停止此会话中的消息传送,并使用最早的未确认消息重启消息传送。
所有使用方都按串行顺序传送消息。 确认已接收消息将自动确认所有已经传送到客户端的消息。
重启会话将导致会话采取以下操作:
- 停止消息传送
- 将所有可能已传送但未确认的消息标记为“重新传送”
- 重启传送序列,包括所有以前已传送的未确认消息。重新传送的消息不必完全按照其最初的传送顺序传送。
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法停止和重启消息传送。 |
Throws | IllegalStateException: 如果该方法由事务性会话调用。 |
recover
void recover() throws JMSException
- Stops message delivery in this session, and restarts message delivery
with the oldest unacknowledged message.
All consumers deliver messages in a serial order. Acknowledging a received message automatically acknowledges all messages that have been delivered to the client.
Restarting a session causes it to take the following actions:
- Stop message delivery
- Mark all messages that might have been delivered but not acknowledged as "redelivered"
- Restart the delivery sequence including all unacknowledged messages that had been previously delivered. Redelivered messages do not have to be delivered in exactly their original delivery order.
- Throws:
JMSException
- if the JMS provider fails to stop and restart message delivery due to some internal error.IllegalStateException
- if the method is called by a transacted session.
public MessageListener
getMessageListener() throws JMSException
返回会话的标识消息侦听器(可选)。
return | 与此会话关联的消息侦听器 |
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法获取消息侦听器。 |
See also | setMessageListener, javax.jms.ServerSessionPool, javax.jms.ServerSession |
getMessageListener
MessageListener getMessageListener() throws JMSException
- Returns the session's distinguished message listener (optional).
- Returns:
- the message listener associated with this session
- Throws:
JMSException
- if the JMS provider fails to get the message listener due to an internal error.- See Also:
setMessageListener(javax.jms.MessageListener)
,ServerSessionPool
,ServerSession
public void
setMessageListener(MessageListener listener) throws JMSException
设置会话的标识消息侦听器(可选)。
设置标识消息侦听器时,不能使用会话中消息接收的其他形式;但发送消息的所有形式仍得到支持。
这是一个专家级工具,常规 JMS 客户端不使用。
listener | 与此会话关联的消息侦听器 |
Throws | JMSException: 如果 JMS 提供者由于某个内部错误无法设置消息侦听器。 |
See also | getMessageListener, javax.jms.ServerSessionPool, javax.jms.ServerSession |
setMessageListener
void setMessageListener(MessageListener listener) throws JMSException
- Sets the session's distinguished message listener (optional).
When the distinguished message listener is set, no other form of message receipt in the session can be used; however, all forms of sending messages are still supported.
This is an expert facility not used by regular JMS clients.
- Parameters:
listener
- the message listener to associate with this session- Throws:
JMSException
- if the JMS provider fails to set the message listener due to an internal error.- See Also:
getMessageListener()
,ServerSessionPool
,ServerSession
public void
run()
可选操作,仅供 Application Server 使用,普通 JMS 客户端无法使用。
See also | javax.jms.ServerSession |
run
void run()
- Optional operation, intended to be used only by Application Servers,
not by ordinary JMS clients.
- See Also:
ServerSession
public MessageProducer
createProducer(Destination destination) throws JMSException
创建 MessageProducer
以将消息发送到指定目的地。
客户端使用 MessageProducer
对象将消息发送到目的地。由于 Queue
和 Topic
都继承自 Destination
,因此它们可以用在 destination 参数中,以创建 MessageProducer
对象。
destination |
要发送到的 Destination ;如果这是没有指定目的地的生成方,则为 null。 |
Throws | JMSException: 如果会话由于某个内部错误无法创建 MessageProducer。 |
Throws | InvalidDestinationException: 如果指定了无效的目的地。 |
since | 1.1 |
createProducer
MessageProducer createProducer(Destination destination) throws JMSException
- Creates a
MessageProducer
to send messages to the specified destination.A client uses a
MessageProducer
object to send messages to a destination. SinceQueue
andTopic
both inherit fromDestination
, they can be used in the destination parameter to create aMessageProducer
object. - Parameters:
destination
- theDestination
to send to, or null if this is a producer which does not have a specified destination.- Throws:
JMSException
- if the session fails to create a MessageProducer due to some internal error.InvalidDestinationException
- if an invalid destination is specified.- Since:
- 1.1
public MessageConsumer
createConsumer(Destination destination) throws JMSException
为指定目的地创建 MessageConsumer
。
由于 Queue
和 Topic
都继承自 Destination
,因此它们可以用在 destination 参数中,以创建 MessageConsumer
。
destination |
要访问的 Destination 。 |
Throws | JMSException: 如果会话由于某个内部错误无法创建使用方。 |
Throws | InvalidDestinationException: 如果指定了无效的目的地。 |
since | 1.1 |
createConsumer
MessageConsumer createConsumer(Destination destination) throws JMSException
- Creates a
MessageConsumer
for the specified destination. SinceQueue
andTopic
both inherit fromDestination
, they can be used in the destination parameter to create aMessageConsumer
. - Parameters:
destination
- theDestination
to access.- Throws:
JMSException
- if the session fails to create a consumer due to some internal error.InvalidDestinationException
- if an invalid destination is specified.- Since:
- 1.1
public MessageConsumer
createConsumer(Destination destination, String messageSelector) throws JMSException
为指定目的地创建 MessageConsumer
,使用消息选择器。
由于 Queue
和 Topic
都继承自 Destination
,因此它们可以用在 destination 参数中,以创建 MessageConsumer
。
客户端使用 MessageConsumer
对象接收已发送到目的地的消息。
destination |
要访问的 Destination |
messageSelector | 仅传送属性 与消息选择器表达式相匹配的消息。值为 null 或 空字符串表示该消息使用方没有消息选择器 。 |
Throws | JMSException: 如果会话由于某个内部错误无法创建 MessageConsumer。 |
Throws | InvalidDestinationException: 如果指定了无效的目的地。 |
Throws | InvalidSelectorException: 如果消息选择器无效。 |
since | 1.1 |
createConsumer
MessageConsumer createConsumer(Destination destination, String messageSelector) throws JMSException
- Creates a
MessageConsumer
for the specified destination, using a message selector. SinceQueue
andTopic
both inherit fromDestination
, they can be used in the destination parameter to create aMessageConsumer
.A client uses a
MessageConsumer
object to receive messages that have been sent to a destination. - Parameters:
destination
- theDestination
to accessmessageSelector
- only messages with properties matching the message selector expression are delivered. A value of null or an empty string indicates that there is no message selector for the message consumer.- Throws:
JMSException
- if the session fails to create a MessageConsumer due to some internal error.InvalidDestinationException
- if an invalid destination is specified.InvalidSelectorException
- if the message selector is invalid.- Since:
- 1.1
public MessageConsumer
createConsumer(Destination destination, String messageSelector, boolean NoLocal) throws JMSException
为指定目的地创建 MessageConsumer
,使用消息选择器。如果目的地是主题,此方法可以指定是否应将由其自己的连接发布的消息传送给它。
由于 Queue
和 Topic
都继承自 Destination
,因此它们可以用在 destination 参数中,以创建 MessageConsumer
。
客户端使用 MessageConsumer
对象接收已发布到目的地的消息。
在某些情况下,连接可以既发布又订阅主题。使用方 NoLocal
属性允许使用方禁止传送由其自己的连接发布的消息。
此属性的默认值为 False。作为主题的目的地必须支持 noLocal
值。
destination |
要访问的 Destination |
messageSelector | 仅传送属性 与消息选择器表达式相匹配的消息。值为 null 或 空字符串表示该消息使用方没有消息选择器 。 |
NoLocal |
如果为 true 且目的地是主题,则禁止传送由其自己的连接发布的消息。如果目的地为队列,则不指定 NoLocal 的行为。 |
Throws | JMSException: 如果会话由于某个内部错误无法创建 MessageConsumer。 |
Throws | InvalidDestinationException: 如果指定了无效的目的地。 |
Throws | InvalidSelectorException: 如果消息选择器无效。 |
since | 1.1 |
createConsumer
MessageConsumer createConsumer(Destination destination, String messageSelector, boolean NoLocal) throws JMSException
- Creates
MessageConsumer
for the specified destination, using a message selector. This method can specify whether messages published by its own connection should be delivered to it, if the destination is a topic.Since
Queue
andTopic
both inherit fromDestination
, they can be used in the destination parameter to create aMessageConsumer
.A client uses a
MessageConsumer
object to receive messages that have been published to a destination.In some cases, a connection may both publish and subscribe to a topic. The consumer
NoLocal
attribute allows a consumer to inhibit the delivery of messages published by its own connection. The default value for this attribute is False. ThenoLocal
value must be supported by destinations that are topics. - Parameters:
destination
- theDestination
to accessmessageSelector
- only messages with properties matching the message selector expression are delivered. A value of null or an empty string indicates that there is no message selector for the message consumer.NoLocal
- - if true, and the destination is a topic, inhibits the delivery of messages published by its own connection. The behavior forNoLocal
is not specified if the destination is a queue.- Throws:
JMSException
- if the session fails to create a MessageConsumer due to some internal error.InvalidDestinationException
- if an invalid destination is specified.InvalidSelectorException
- if the message selector is invalid.- Since:
- 1.1
public Queue
createQueue(String queueName) throws JMSException
创建给定 Queue
名称的队列身份。
此工具供某些特殊情况使用,这些情况下客户端需要动态操作队列身份。这允许创建具有特定于提供者的名称的队列身份。依赖于此能力的客户端是不可移植的。
注意,此方法不用于创建物理队列。
物理创建队列是一项管理任务,不应由 JMS API 发起。有一个例外是创建临时队列,它可以使用 createTemporaryQueue
方法实现。
queueName |
此 Queue 的名称 |
return |
具有给定名称的 Queue |
Throws | JMSException: 如果会话由于某个内部错误无法创建队列。 |
since | 1.1 |
createQueue
Queue createQueue(String queueName) throws JMSException
- Creates a queue identity given a
Queue
name.This facility is provided for the rare cases where clients need to dynamically manipulate queue identity. It allows the creation of a queue identity with a provider-specific name. Clients that depend on this ability are not portable.
Note that this method is not for creating the physical queue. The physical creation of queues is an administrative task and is not to be initiated by the JMS API. The one exception is the creation of temporary queues, which is accomplished with the
createTemporaryQueue
method. - Parameters:
queueName
- the name of thisQueue
- Returns:
- a
Queue
with the given name - Throws:
JMSException
- if the session fails to create a queue due to some internal error.- Since:
- 1.1
public Topic
createTopic(String topicName) throws JMSException
创建给定 Topic
名称的主题身份。
此工具供某些特殊情况使用,这些情况下客户端需要动态操作主题身份。这允许创建具有特定于提供者的名称的主题身份。依赖于此能力的客户端是不可移植的。
注意,此方法不用于创建物理主题。物理创建主题是一项管理任务,不应由 JMS API 发起。有一个例外是创建临时主题,它可以使用 createTemporaryTopic
方法实现。
topicName |
此 Topic 的名称 |
return |
具有给定名称的 Topic |
Throws | JMSException: 如果会话由于某个内部错误无法创建主题。 |
since | 1.1 |
createTopic
Topic createTopic(String topicName) throws JMSException
- Creates a topic identity given a
Topic
name.This facility is provided for the rare cases where clients need to dynamically manipulate topic identity. This allows the creation of a topic identity with a provider-specific name. Clients that depend on this ability are not portable.
Note that this method is not for creating the physical topic. The physical creation of topics is an administrative task and is not to be initiated by the JMS API. The one exception is the creation of temporary topics, which is accomplished with the
createTemporaryTopic
method. - Parameters:
topicName
- the name of thisTopic
- Returns:
- a
Topic
with the given name - Throws:
JMSException
- if the session fails to create a topic due to some internal error.- Since:
- 1.1
public TopicSubscriber
createDurableSubscriber(Topic topic, String name) throws JMSException
创建指定主题的持久订阅者。
如果客户端需要接收所有在主题上发布的消息,包括订阅者处于非活动状态时发布的消息,它使用持久 TopicSubscriber
。JMS 提供者保留此持久订阅的记录并确保来自该主题发布者的所有消息能够一直保留,直到它们得到此持久订阅者的确认或消息过期。
具有持久订阅者的会话必须总是提供相同的客户端标识符。此外,每个客户端必须指定一个名称,该名称能够唯一地标识(在客户端标识符内)它所创建的每个持久订阅。一次只有一个会话可以拥有特定持久订阅的 TopicSubscriber
。
客户端可以通过创建具有相同名称和新主题和/或消息选择器的持久 TopicSubscriber
来更改现有持久订阅。更改持久订阅者等效于取消订阅(删除)旧的持久订阅,并创建一个新的持久订阅。
在某些情况下,连接可以既发布又订阅主题。订阅者 NoLocal
属性允许订阅者禁止传送由其自己的连接发布的消息。
此属性的默认值为 false。
topic |
要订阅的非临时 Topic |
name | 用于标识此订阅的名称 |
Throws | JMSException: 如果会话由于某个内部错误无法创建订阅者。 |
Throws | InvalidDestinationException: 如果指定了无效的主题。 |
since | 1.1 |
createDurableSubscriber
TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException
- Creates a durable subscriber to the specified topic.
If a client needs to receive all the messages published on a topic, including the ones published while the subscriber is inactive, it uses a durable
TopicSubscriber
. The JMS provider retains a record of this durable subscription and insures that all messages from the topic's publishers are retained until they are acknowledged by this durable subscriber or they have expired.Sessions with durable subscribers must always provide the same client identifier. In addition, each client must specify a name that uniquely identifies (within client identifier) each durable subscription it creates. Only one session at a time can have a
TopicSubscriber
for a particular durable subscription.A client can change an existing durable subscription by creating a durable
TopicSubscriber
with the same name and a new topic and/or message selector. Changing a durable subscriber is equivalent to unsubscribing (deleting) the old one and creating a new one.In some cases, a connection may both publish and subscribe to a topic. The subscriber
NoLocal
attribute allows a subscriber to inhibit the delivery of messages published by its own connection. The default value for this attribute is false. - Parameters:
topic
- the non-temporaryTopic
to subscribe toname
- the name used to identify this subscription- Throws:
JMSException
- if the session fails to create a subscriber due to some internal error.InvalidDestinationException
- if an invalid topic is specified.- Since:
- 1.1
public TopicSubscriber
createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal) throws JMSException
创建指定主题的持久订阅者,使用消息选择器并指定是否应将由其自己的连接发布的消息传送给它。
如果客户端需要接收所有在主题上发布的消息,包括订阅者处于非活动状态时发布的消息,它使用持久 TopicSubscriber
。JMS 提供者保留此持久订阅的记录并确保来自该主题发布者的所有消息能够一直保留,直到它们得到此持久订阅者的确认或消息过期。
具有持久订阅者的会话必须总是提供相同的客户端标识符。此外,每个客户端必须指定一个名称,该名称能够唯一地标识(在客户端标识符内)它所创建的每个持久订阅。一次只有一个会话可以拥有特定持久订阅的 TopicSubscriber
。
非活动持久订阅者是存在但当前没有与之关联的消息使用方的订阅者。
客户端可以通过创建具有相同名称和新主题和/或消息选择器的持久 TopicSubscriber
来更改现有持久订阅。更改持久订阅者等效于取消订阅(删除)旧的持久订阅,并创建一个新的持久订阅。
topic |
要订阅的非临时 Topic |
name | 用于标识此订阅的名称 |
messageSelector | 仅传送属性与消息选择器表达式相匹配的消息。值为 null 或空字符串表示该消息使用方没有消息选择器。 |
noLocal | 如果设置,则禁止传送由其自己的连接发布的消息 |
Throws | JMSException: 如果会话由于某个内部错误无法创建订阅者。 |
Throws | InvalidDestinationException: 如果指定了无效的主题。 |
Throws | InvalidSelectorException: 如果消息选择器无效。 |
since | 1.1 |
createDurableSubscriber
TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal) throws JMSException
- Creates a durable subscriber to the specified topic, using a
message selector and specifying whether messages published by its
own connection should be delivered to it.
If a client needs to receive all the messages published on a topic, including the ones published while the subscriber is inactive, it uses a durable
TopicSubscriber
. The JMS provider retains a record of this durable subscription and insures that all messages from the topic's publishers are retained until they are acknowledged by this durable subscriber or they have expired.Sessions with durable subscribers must always provide the same client identifier. In addition, each client must specify a name which uniquely identifies (within client identifier) each durable subscription it creates. Only one session at a time can have a
TopicSubscriber
for a particular durable subscription. An inactive durable subscriber is one that exists but does not currently have a message consumer associated with it.A client can change an existing durable subscription by creating a durable
TopicSubscriber
with the same name and a new topic and/or message selector. Changing a durable subscriber is equivalent to unsubscribing (deleting) the old one and creating a new one. - Parameters:
topic
- the non-temporaryTopic
to subscribe toname
- the name used to identify this subscriptionmessageSelector
- only messages with properties matching the message selector expression are delivered. A value of null or an empty string indicates that there is no message selector for the message consumer.noLocal
- if set, inhibits the delivery of messages published by its own connection- Throws:
JMSException
- if the session fails to create a subscriber due to some internal error.InvalidDestinationException
- if an invalid topic is specified.InvalidSelectorException
- if the message selector is invalid.- Since:
- 1.1
public QueueBrowser
createBrowser(Queue queue) throws JMSException
创建 QueueBrowser
对象以查看指定队列上的消息。
queue |
要访问的 queue |
Throws | JMSException: 如果会话由于某个内部错误无法创建浏览器。 |
Throws | InvalidDestinationException: 如果指定了无效的目的地。 |
since | 1.1 |
createBrowser
QueueBrowser createBrowser(Queue queue) throws JMSException
- Creates a
QueueBrowser
object to peek at the messages on the specified queue. - Parameters:
queue
- thequeue
to access- Throws:
JMSException
- if the session fails to create a browser due to some internal error.InvalidDestinationException
- if an invalid destination is specified- Since:
- 1.1
public QueueBrowser
createBrowser(Queue queue, String messageSelector) throws JMSException
创建 QueueBrowser
对象以查看使用消息选择器的指定队列上的消息。
queue |
要访问的 queue |
messageSelector | 仅传送属性 与消息选择器表达式相匹配的消息。值为 null 或 空字符串表示该消息使用方没有消息选择器 。 |
Throws | JMSException: 如果会话由于某个内部错误无法创建浏览器。 |
Throws | InvalidDestinationException: 如果指定了无效的目的地。 |
Throws | InvalidSelectorException: 如果消息选择器无效。 |
since | 1.1 |
createBrowser
QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException
- Creates a
QueueBrowser
object to peek at the messages on the specified queue using a message selector. - Parameters:
queue
- thequeue
to accessmessageSelector
- only messages with properties matching the message selector expression are delivered. A value of null or an empty string indicates that there is no message selector for the message consumer.- Throws:
JMSException
- if the session fails to create a browser due to some internal error.InvalidDestinationException
- if an invalid destination is specifiedInvalidSelectorException
- if the message selector is invalid.- Since:
- 1.1
public TemporaryQueue
createTemporaryQueue() throws JMSException
创建 TemporaryQueue
对象。其生命周期将是 Connection
的生命周期,除非提前删除该对象。
return | 临时队列身份 |
Throws | JMSException: 如果会话由于某个内部错误无法创建临时队列。 |
since | 1.1 |
createTemporaryQueue
TemporaryQueue createTemporaryQueue() throws JMSException
- Creates a
TemporaryQueue
object. Its lifetime will be that of theConnection
unless it is deleted earlier. - Returns:
- a temporary queue identity
- Throws:
JMSException
- if the session fails to create a temporary queue due to some internal error.- Since:
- 1.1
public TemporaryTopic
createTemporaryTopic() throws JMSException
创建 TemporaryTopic
对象。其生命周期将是 Connection
的生命周期,除非提前删除该对象。
return | 临时主题身份 |
Throws | JMSException: 如果会话由于某个内部错误无法创建临时主题。 |
since | 1.1 |
createTemporaryTopic
TemporaryTopic createTemporaryTopic() throws JMSException
- Creates a
TemporaryTopic
object. Its lifetime will be that of theConnection
unless it is deleted earlier. - Returns:
- a temporary topic identity
- Throws:
JMSException
- if the session fails to create a temporary topic due to some internal error.- Since:
- 1.1
public void
unsubscribe(String name) throws JMSException
取消订阅客户端已创建的持久订阅。
此方法删除其提供者代表订阅者维持的状态。
在该订阅存在活动的 MessageConsumer
或 TopicSubscriber
时,或者当已使用的消息是挂起事务的一部分或尚未在会话中得到确认时,客户端删除持久订阅是错误的。
name | 用于标识此订阅的名称 |
Throws | JMSException: 如果会话由于某个内部错误无法取消对持久订阅的订阅。 |
Throws | InvalidDestinationException: 如果指定了无效的订阅名称。 |
since | 1.1 |
unsubscribe
void unsubscribe(String name) throws JMSException
- Unsubscribes a durable subscription that has been created by a client.
This method deletes the state being maintained on behalf of the subscriber by its provider.
It is erroneous for a client to delete a durable subscription while there is an active
MessageConsumer
orTopicSubscriber
for the subscription, or while a consumed message is part of a pending transaction or has not been acknowledged in the session. - Parameters:
name
- the name used to identify this subscription- Throws:
JMSException
- if the session fails to unsubscribe to the durable subscription due to some internal error.InvalidDestinationException
- if an invalid subscription name is specified.- Since:
- 1.1
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!