Class: JMSContext

JMSContext

Class that works as a simplified context for producing and consuming messages.

new JMSContext()

This method is not meant to be used directly. Creates a JMSContext object that works as a simplified context for producing and consuming messages.

Method Summary

acknowledge
Acknowledges all messages consumed by the JMSContext's session.
close
Closes the context.
commit
Commits all messages done in this transaction.
createBytesMessage
Creates a new empty BytesMessage.
createConsumer
Creates a JMSConsumer for the specified destination, using a message selector.
createContext
Creates a new JMSContext object based on the same connection this JMSContext is based on.
createDurableConsumer
Creates a new durable JMSConsumer object for receiving messages on a specific Topic.
createMapMessage
Creates a new empty MapMessage.
createMessage
Creates a Message object.
createObjectMessage
Creates a new ObjectMessage with the specified object and class fully-qualified name as its payload.
createProducer
Creates a JMSProducer to send messages to a destination.
createQueue
Creates a new Queue object with the specified queue name.
createSharedConsumer
Creates a new shared JMSConsumer object for receiving messages on a specific Topic.
createSharedDurableConsumer
Creates a new shared durable JMSConsumer object for receiving messages on a specific Topic.
createTemporaryQueue
Creates a TemporaryQueue object.
createTemporaryTopic
Creates a TemporaryTopic object.
createTextMessage
Creates a new TextMessage with the specified string as its payload.
createTopic
Creates a new Topic object with the specified topic name.
getAutoStart
Returns whether the connection this JMSContext is based on will be started automatically when a consumer is created.
getClientID
Gets the client identifier for the connection this JMSContext is based on.
getExceptionListener
Gets the ExceptionListener object for this connection.
getSessionMode
Returns the session mode of the context.
getTransacted
Indicates whether the context is in transacted mode.
recover
Stops message delivery in this context, and restarts message delivery with the oldest unacknowledged message.
rollback
Rolls back any messages done in this transaction.
setAutoStart
Specifies whether the connection this JMSContext is based on will be started automatically when a consumer is created.
setClientID
Sets the client identifier for the connection this JMSContext is based on.
setExceptionListener
Sets an exception listener for the connection this JMSContext is based on.
start
Starts (or restarts) the delivery of incoming messages for the connection this JMSContext is based on.
stop
Temporarily stops the delivery of incoming messages for the connection this JMSContext is based on.
unsubscribe
Unsubscribes a durable subscription previously created with the specified name.

Method Detail

acknowledge()

Acknowledges all messages consumed by the JMSContext's session. This method is for use when the session has an acknowledgement mode of "CLIENT_ACK" or "INDIVIDUAL_ACK". If the session is transacted or has another acknowledgement mode calling this method has no effect.
This method has identical behaviour to the Message#acknowledge method on Message.

close()

Closes the context. All message producers and consumers will be stopped and their subsequent use will cause an IllegalStateException. A call to JMSContext#close on a context that has already been closed is ignored.
Implementation note: underlying subscriptions are unsubscribed and deleted. If the connection was created through a ConnectionFactory the underlying LightstreamerClient connection is also disconnected. This means any message being sent (JMS messages, acknowledges, unsubscriptions, etc.) may get lost if the library did not have enough time to deliver them.

commit()

Commits all messages done in this transaction.

createBytesMessage() → {BytesMessage}

Creates a new empty BytesMessage.
Returns:
Type
BytesMessage

createConsumer(destination, messageSelector, noLocal) → {JMSConsumer}

Creates a JMSConsumer for the specified destination, using a message selector.
Parameters:
Name Type Description
destination Destination destination from which the consumer must receive messages.
messageSelector String specifies the optional selector, e.g. the rule to be applied to messages being received to filter them or not. See JMS specifications for more information on message selectors.
noLocal Boolean if true, and the destination is a topic, then the JMSConsumer will not receive messages published to the topic by its own connection. The default value of this argument is false.
Returns:
Type
JMSConsumer

createContext(sessionMode) → {JMSContext}

Creates a new JMSContext object based on the same connection this JMSContext is based on.
Parameters:
Name Type Description
sessionMode String specifies the session mode. Can be one of the following: "TRANSACTED", "PRE_ACK", "AUTO_ACK", "CLIENT_ACK", "DUPS_OK" or "INDIVIDUAL_ACK". See JMS Extender documentation for more information.
Returns:
Type
JMSContext

createDurableConsumer(topic, name, messageSelector, noLocal) → {JMSConsumer}

Creates a new durable JMSConsumer object for receiving messages on a specific Topic. See JMS specifications for differences between durable and non durable consumers.
Parameters:
Name Type Description
topic Topic topic from which the consumer must receive messages.
name String name of the durable subscription. See JMS specifications for more information.
messageSelector String specifies the optional selector, e.g. the rule to be applied to messages being received to filter them or not. See JMS specifications for more information on message selectors.
noLocal Boolean if true the JMSConsumer will not receive messages published to the topic by its own connection. The default value of this argument is false.
Returns:
Type
JMSConsumer

createMapMessage() → {MapMessage}

Creates a new empty MapMessage.
Returns:
Type
MapMessage

createMessage() → {Message}

Creates a Message object. The Message class is the root class of all JMS messages. A Message object holds all the standard message header information. It can be sent when a message containing only header information is sufficient.
Returns:
Type
Message

createObjectMessage(object, classFQN) → {ObjectMessage}

Creates a new ObjectMessage with the specified object and class fully-qualified name as its payload.
Parameters:
Name Type Description
object Object desired object payload for the message.
classFQN String fully-qualified class name of the payload object.
Returns:
Type
ObjectMessage

createProducer() → {JMSProducer}

Creates a JMSProducer to send messages to a destination. The destination is specified on the producer itself.
Returns:
Type
JMSProducer

createQueue(queueName) → {Queue}

Creates a new Queue object with the specified queue name.
Parameters:
Name Type Description
queueName String name of the queue.
Returns:
Type
Queue

createSharedConsumer(topic, sharedSubscriptionName, messageSelector) → {JMSConsumer}

Creates a new shared JMSConsumer object for receiving messages on a specific Topic. See JMS specifications for differences between shared and non shared consumers.
Parameters:
Name Type Description
topic Topic topic from which the consumer must receive messages.
sharedSubscriptionName String name of the shared subscription. See JMS specifications for more information.
messageSelector String specifies the optional selector, e.g. the rule to be applied to messages being received to filter them or not. See JMS specifications for more information on message selectors.
Returns:
Type
JMSConsumer

createSharedDurableConsumer(topic, name, messageSelector) → {JMSConsumer}

Creates a new shared durable JMSConsumer object for receiving messages on a specific Topic. See JMS specifications for differences between durable, non durable, shared and non shared consumers.
Parameters:
Name Type Description
topic Topic topic from which the consumer must receive messages.
name String name of the shared durable subscription. See JMS specifications for more information.
messageSelector String specifies the optional selector, e.g. the rule to be applied to messages being received to filter them or not. See JMS specifications for more information on message selectors.
Returns:
Type
JMSConsumer

createTemporaryQueue(onTempQueueCreated, onTempQueueFailed) → {TemporaryQueue}

Creates a TemporaryQueue object. Its lifetime will be that of the Connection this context is based, unless it is deleted earlier.
Implementation note: due to limitations of Javascript this method can't return a temp queue synchronously, the queue will be delivered asynchronously through the specified callback.
Parameters:
Name Type Description
onTempQueueCreated function the callback that will be invoked when the temp queue is created. Takes one argument: the TemporaryQueue object.
onTempQueueFailed function the callback that will be invoked when the temp queue creation fails. Takes one argument: an exception.
Returns:
Type
TemporaryQueue

createTemporaryTopic(onTempTopicCreated, onTempTopicFailed) → {TemporaryTopic}

Creates a TemporaryTopic object. Its lifetime will be that of the Connection this context is based on, unless it is deleted earlier.
Implementation note: due to limitations of Javascript this method can't return a temp topic synchronously, the topic will be delivered asynchronously through the specified callback.
Parameters:
Name Type Description
onTempTopicCreated function the callback that will be invoked when the temp topic is created. Takes one argument: the TemporaryQueue object.
onTempTopicFailed function the callback that will be invoked when the temp topic creation fails. Takes one argument: an exception.
Returns:
Type
TemporaryTopic

createTextMessage(text) → {TextMessage}

Creates a new TextMessage with the specified string as its payload.
Parameters:
Name Type Description
text String desired string payload for the message.
Returns:
Type
TextMessage

createTopic(topicName) → {Topic}

Creates a new Topic object with the specified topic name.
Parameters:
Name Type Description
topicName String name of the topic.
Returns:
Type
Topic

getAutoStart() → {Boolean}

Returns whether the connection this JMSContext is based on will be started automatically when a consumer is created.
Returns:
Type
Boolean

getClientID() → {String}

Gets the client identifier for the connection this JMSContext is based on. See JMS specifications for more information.
Returns:
Type
String

getExceptionListener() → {ExceptionListener}

Gets the ExceptionListener object for this connection.
Returns:
Type
ExceptionListener

getSessionMode() → {String}

Returns the session mode of the context. The session mode is set at the time that the context is created.
Returns:
Type
String

getTransacted() → {Boolean}

Indicates whether the context is in transacted mode.
Returns:
Type
Boolean

recover()

Stops message delivery in this context, and restarts message delivery with the oldest unacknowledged message. Redelivered messages do not have to be delivered in exactly their original delivery order. See JMS specifications for more information.

rollback()

Rolls back any messages done in this transaction.

setAutoStart(autoStart)

Specifies whether the connection this JMSContext is based on will be started automatically when a consumer is created. This is the default behaviour, and it may be disabled by calling this method with a value of false.
Parameters:
Name Type Description
autoStart Boolean Whether the connection this JMSContext is based on will be automatically started when a consumer is created.

setClientID(clientID)

Sets the client identifier for the connection this JMSContext is based on. See JMS specifications for more information.
Implementation note: scalability considerations apply when the client ID is set, see JMS Extender documentation.
Parameters:
Name Type Description
clientID String the unique client identifier

setExceptionListener(exceptionListener)

Sets an exception listener for the connection this JMSContext is based on. Many common JMS exceptions will be delivered asynchronously through this listener.
Parameters:
Name Type Description
exceptionListener ExceptionListener the exception listener meant to receive exceptions.

start()

Starts (or restarts) the delivery of incoming messages for the connection this JMSContext is based on. A call to JMSContext#start on a context that has already been started is ignored.

stop()

Temporarily stops the delivery of incoming messages for the connection this JMSContext is based on. Delivery can be restarted using JMSContext#start method. A call to JMSContext#stop on a context that has already been stopped is ignored.
Stopping a connection has no effect on its ability to send messages.
Implementation note: underlying subscriptions are unsubscribed but their item names are kept for a later restart.

unsubscribe(name)

Unsubscribes a durable subscription previously created with the specified name. See JMS specifications for more information on durable subscriptions.
Implementation note: if there's still an open consumer on the subscription, the unsubscribe will be automatically postponed to when the consumer will be closed.
Parameters:
Name Type Description
name String name used to identify this subscription.