Habari Client for ActiveMQ 3.0
Delphi and Free Pascal client library for the Apache ActiveMQ open source message broker

TBTJMSSession Class Reference

A Session object is a single-threaded context for producing and consuming messages. More...

Inheritance diagram for TBTJMSSession:
ISession

List of all members.

Public Member Functions

 SetTransformer (const IMessageTransformer Transformer)
 Set the message transformer.
 Commit ()
 If this is a transactional session then commit all message send and acknowledgements for producers and consumers in this session.
IBytesMessage CreateBytesMessage ()
 Creates a IBytesMessage object.
IMessage CreateMessage ()
 Creates a IMessage object.
ITextMessage CreateTextMessage ()
 Creates a ITextMessage object.
ITextMessage CreateTextMessage (const WideString Text)
 Creates an initialized ITextMessage object.
IMapMessage CreateMapMessage ()
 Creates a MapMessage object.
IMessageConsumer CreateConsumer (const IDestination Destination)
 Creates a IMessageConsumer for the specified destination.
IMessageConsumer CreateConsumer (const IDestination Destination, const string MessageSelector)
 Creates a IMessageConsumer for the specified destination, using a message selector.
IMessageConsumer CreateConsumer (const IDestination Destination, const string MessageSelector, const Boolean NoLocal)
 Creates IMessageConsumer for the specified destination, using a message selector.
IMessageConsumer CreateConsumer (const IDestination Destination, const string MessageSelector, const Boolean NoLocal, const IMessageListener MessageListener)
 Creates IMessageConsumer for the specified destination, using a message selector.
IObjectMessage CreateObjectMessage ()
 Creates an IObjectMessage object.
IObjectMessage CreateObjectMessage (const TObject AObject)
 Creates an initialized IObjectMessage object.
ITopicSubscriber CreateDurableSubscriber (const ITopic Topic, string Name)
 Creates a durable subscriber to the specified topic.
ITopicSubscriber CreateDurableSubscriber (const ITopic Topic, string Name, const string MessageSelector, const 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.
IMessageProducer CreateProducer (const IDestination Destination)
 Creates a producer of messages on a given destination.
IQueue CreateQueue (const string QueueName)
 Creates a queue identity given a IQueue name.
ITopic CreateTopic (const string TopicName)
 Creates a topic identity given a ITopic name.
ITemporaryQueue CreateTemporaryQueue ()
 Creates a TemporaryQueue object.
ITemporaryTopic CreateTemporaryTopic ()
 Creates a TemporaryTopic object.
 Rollback ()
 If this is a transactional session then rollback all message send and acknowledgements for producers and consumers in this session.
 Send (const IMessageProducer Producer, const IDestination Destination, const IMessage Message, const TJMSDeliveryMode DeliveryMode, const Byte Priority, const Cardinal TimeToLive, const Integer SendTimeOut)
 Sends the message for dispatch by the broker.
 Unsubscribe (const string Destination, const string Name)
 Unsubscribes a durable subscription that has been created by a client.

Public Attributes

TAcknowledgementMode AcknowledgeMode
 The acknowledgement mode of the session.
TBTJMSConnection Connection
 The connection of the session.
Boolean Running
 Returns True if the session has started.
Boolean Transacted
 Whether the session uses transactions.
TBTTransactionContext TransactionContext
 The transaction context of the session.

Protected Member Functions

 CheckClosed ()
 Check if the session is closed.

Protected Attributes

TSessionID SessionID

Detailed Description

A Session object is a single-threaded context for producing and consuming messages.

A session serves several purposes:

  • It is a factory for its message producers and consumers.
  • It supplies provider-optimized message factories.
  • It provides a way to create IQueue or ITopic 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.

A session can create and service multiple message producers and consumers.

One typical use is to have a thread block on a synchronous IMessageConsumer until a message arrives. The thread may then use one or more of the ISession'sIMessageProducers.

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.


Member Function Documentation

TBTJMSSession::CheckClosed ( ) [protected]

Check if the session is closed.

It is used for ensuring that the session is open before performing various operations.

Exceptions:
EIllegalStateExceptionif the Session is closed
TBTJMSSession::Commit ( )

If this is a transactional session then commit all message send and acknowledgements for producers and consumers in this session.

Exceptions:
EJMSException
IBytesMessage TBTJMSSession::CreateBytesMessage ( )

Creates a IBytesMessage object.

A IBytesMessage object is used to send a message containing a stream of uninterpreted bytes.

Returns:
the IBytesMessage
IMessageConsumer TBTJMSSession::CreateConsumer ( const IDestination  Destination)

Creates a IMessageConsumer for the specified destination.

Since IQueue and ITopic both inherit from IDestination, they can be used in the destination parameter to create a IMessageConsumer.

Parameters:
Destinationthe IDestination to access.
Returns:
the IMessageConsumer
IMessageConsumer TBTJMSSession::CreateConsumer ( const IDestination  Destination,
const string  MessageSelector 
)

Creates a IMessageConsumer for the specified destination, using a message selector.

Since IQueue and ITopic both inherit from IDestination, they can be used in the destination parameter to create a IMessageConsumer.

A client uses a IMessageConsumer object to receive messages that have been sent to a destination.

Parameters:
Destinationthe IDestination to access
MessageSelectoronly messages with properties matching the message selector expression are delivered. An empty string indicates that there is no message selector for the message consumer.
Returns:
the MessageConsumer
IMessageConsumer TBTJMSSession::CreateConsumer ( const IDestination  Destination,
const string  MessageSelector,
const Boolean  NoLocal 
)

Creates IMessageConsumer 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 IQueue and ITopic both inherit from IDestination, they can be used in the destination parameter to create a IMessageConsumer.

A client uses a IMessageConsumer 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. The noLocal value must be supported by destinations that are topics.

Parameters:
Destinationthe IDestination to access
MessageSelectoronly messages with properties matching the message selector expression are delivered. 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 for NoLocal is not specified if the destination is a queue.
Returns:
the MessageConsumer
IMessageConsumer TBTJMSSession::CreateConsumer ( const IDestination  Destination,
const string  MessageSelector,
const Boolean  NoLocal,
const IMessageListener  MessageListener 
)

Creates IMessageConsumer 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 IQueue and ITopic both inherit from IDestination, they can be used in the destination parameter to create a IMessageConsumer.

A client uses a IMessageConsumer 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. The noLocal value must be supported by destinations that are topics.

Parameters:
Destinationthe IDestination to access
MessageSelectoronly messages with properties matching the message selector expression are delivered. 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 for NoLocal is not specified if the destination is a queue.
MessageListenerthe listener to use for async consumption of messages
Returns:
the MessageConsumer
ITopicSubscriber TBTJMSSession::CreateDurableSubscriber ( const ITopic  Topic,
string  Name 
)

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

Note:
For durable topic subscriptions you must specify the same clientId on the connection and subcriptionName on the subscribe.
See also:
http://activemq.apache.org/stomp.html
Parameters:
Topic- the non-temporary ITopic to subscribe to
Name- the name used to identify this subscription
Returns:
the ITopicSubscriber
Exceptions:
JMSException- if the session fails to create a subscriber due to some internal error.
EInvalidDestinationException- if an invalid topic is specified.
Since:
1.4
ITopicSubscriber TBTJMSSession::CreateDurableSubscriber ( const ITopic  Topic,
string  Name,
const string  MessageSelector,
const 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.

Since:
2.4
IMapMessage TBTJMSSession::CreateMapMessage ( )

Creates a MapMessage object.

A MapMessage object is used to send a self-defining set of name-value pairs, where names are String objects and values are primitive values in the Java programming language.

Since:
2.2
Returns:
an IMapMessage
IMessage TBTJMSSession::CreateMessage ( )

Creates a IMessage object.

The IMessage interface is the root interface of all JMS messages. A IMessage object holds all the standard message header information. It can be sent when a message containing only header information is sufficient.

Returns:
an IMessage
IObjectMessage TBTJMSSession::CreateObjectMessage ( )

Creates an IObjectMessage object.

An IObjectMessage object is used to send a message that contains a serializable Java object.

IObjectMessage TBTJMSSession::CreateObjectMessage ( const TObject  AObject)

Creates an initialized IObjectMessage object.

An IObjectMessage object is used to send a message that contains a serializable Java object.

Parameters:
AObjectthe object to use to initialize this message
IQueue TBTJMSSession::CreateQueue ( const string  QueueName)

Creates a queue identity given a IQueue 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.

Parameters:
QueueNamethe name of this IQueue
Returns:
a IQueue with the given name
ITemporaryQueue TBTJMSSession::CreateTemporaryQueue ( )

Creates a TemporaryQueue object.

Its lifetime will be that of the Connection unless it is deleted earlier.

Since:
2.3
See also:
http://download.oracle.com/javaee/5/api/javax/jms/Session.html#createTemporaryQueue()
ITemporaryTopic TBTJMSSession::CreateTemporaryTopic ( )

Creates a TemporaryTopic object.

Its lifetime will be that of the Connection unless it is deleted earlier.

Since:
2.3
See also:
http://download.oracle.com/javaee/5/api/javax/jms/Session.html#createTemporaryTopic()
ITextMessage TBTJMSSession::CreateTextMessage ( )

Creates a ITextMessage object.

A ITextMessage object is used to send a message containing a String object.

Returns:
an ITextMessage
ITextMessage TBTJMSSession::CreateTextMessage ( const WideString  Text)

Creates an initialized ITextMessage object.

A ITextMessage object is used to send a message containing a String.

Parameters:
Textthe string used to initialize this message
Returns:
an ITextMessage
ITopic TBTJMSSession::CreateTopic ( const string  TopicName)

Creates a topic identity given a ITopic 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.

Parameters:
TopicNamethe name of this ITopic
Returns:
a ITopic with the given name
TBTJMSSession::Rollback ( )

If this is a transactional session then rollback all message send and acknowledgements for producers and consumers in this session.

Exceptions:
EJMSException
TBTJMSSession::Send ( const IMessageProducer  Producer,
const IDestination  Destination,
const IMessage  Message,
const TJMSDeliveryMode  DeliveryMode,
const Byte  Priority,
const Cardinal  TimeToLive,
const Integer  SendTimeOut 
)

Sends the message for dispatch by the broker.

Parameters:
Producer- message producer.
Destination- message destination.
Message- message to be sent.
DeliveryMode- JMS message delivery mode.
Priority- message priority.
TimeToLive- message expiration.
SendTimeOut- send time out.
TBTJMSSession::SetTransformer ( const IMessageTransformer  Transformer)

Set the message transformer.

See also:
http://activemq.apache.org/message-transformation.html
TBTJMSSession::Unsubscribe ( const string  Destination,
const string  Name 
)

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 or TopicSubscriber for the subscription, or while a consumed message is part of a pending transaction or has not been acknowledged in the session.

Parameters:
Destination- the destination name
Name- the name used to identify this subscription
Exceptions:
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.4

Member Data Documentation

TAcknowledgementMode TBTJMSSession::AcknowledgeMode

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.

amTransactional This value is returned from the method getAcknowledgeMode if the session is transacted.

amDupsOkAcknowledge This acknowledgment mode instructs the session to lazily acknowledge the delivery of messages.

amClientAcknowledge With this acknowledgment mode, the client acknowledges a consumed message by calling the message's acknowledge method.

amAutoAcknowledge 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:
GetAcknowledgeMode For reading

The connection of the session.

See also:
GetConnection For reading
SetConnection For writing

Returns True if the session has started.

See also:
FStarted For reading
TSessionID TBTJMSSession::SessionID [protected]
See also:
FSessionID For reading

Whether the session uses transactions.

See also:
GetTransacted For reading
TBTTransactionContext TBTJMSSession::TransactionContext

The transaction context of the session.

See also:
FTransactionContext For reading
 All Classes Functions Variables