Contents
class solace.Session
This class is not exposed for construction by API users. Applications must use solace.SolclientFactory.createSession to create a session.
Represents a client Session.
Session provides these major functions:
- Subscriber control, such as updating subscriptions;
- Publishes both Direct and Guaranteed Messages to the router;
- Receives direct messages from the router.
The Session object is an EventEmitter, and will emit events with event names from solace.SessionEventCode when Session events occur. Each session event can be subscribed using solace.Session#on with the corresponding solace.SessionEventCode. If any of the registered event listeners throw an exception, the exception will be emitted on the 'error' event.
Fires
- solace.SessionEventCode#event:ACKNOWLEDGED_MESSAGE
- solace.SessionEventCode#event:CAN_ACCEPT_DATA
- solace.SessionEventCode#event:CONNECT_FAILED_ERROR
- solace.SessionEventCode#event:DISCONNECTED
- solace.SessionEventCode#event:DOWN_ERROR
- solace.SessionEventCode#event:GUARANTEED_MESSAGE_PUBLISHER_DOWN
- solace.SessionEventCode#event:MESSAGE
- solace.SessionEventCode#event:PROPERTY_UPDATE_ERROR
- solace.SessionEventCode#event:PROPERTY_UPDATE_OK
- solace.SessionEventCode#event:RECONNECTED_NOTICE
- solace.SessionEventCode#event:RECONNECTING_NOTICE
- solace.SessionEventCode#event:REJECTED_MESSAGE_ERROR
- solace.SessionEventCode#event:REPUBLISHING_UNACKED_MESSAGES
- solace.SessionEventCode#event:SUBSCRIPTION_ERROR
- solace.SessionEventCode#event:SUBSCRIPTION_OK
- solace.SessionEventCode#event:UNSUBSCRIBE_TE_TOPIC_ERROR
- solace.SessionEventCode#event:UNSUBSCRIBE_TE_TOPIC_OK
- solace.SessionEventCode#event:UP_NOTICE
- solace.SessionEventCode#event:VIRTUALROUTER_NAME_CHANGED
- solace.SessionEventCode#event:PROVISION_OK
- solace.SessionEventCode#event:PROVISION_ERROR
Constructor Top
Session ( ) |
Static Methods Top
void | replyReceivedCallback ( solace.Session session, solace.Message message, Object userObject ) | |
void | requestFailedCallback ( solace.Session session, solace.RequestError error, Object userObject ) |
Methods Top
void | connect ( ) | |
solace.CacheSession | createCacheSession ( solace.CacheSessionProperties properties ) | |
solace.MessageConsumer | createMessageConsumer ( solace.MessageConsumerProperties | Object consumerProperties ) | |
solace.QueueBrowser | createQueueBrowser ( solace.QueueBrowserProperties | Object browserProperties ) | |
void | deprovisionEndpoint ( solace.QueueDescriptor queueDescriptor, boolean ignoreMisssing, Object | String | null | undefined correlationKey ) | |
void | disconnect ( ) | |
void | dispose ( ) | |
solace.SDTField | getCapability ( solace.CapabilityType capabilityType ) | |
solace.SessionProperties | getSessionProperties ( ) | |
Number | getStat ( solace.StatType statType ) | |
String | getTransportInfo ( ) | |
Boolean | isCapable ( solace.CapabilityType capabilityType ) | |
void | provisionEndpoint ( solace.QueueDescriptor queueDescriptor, solace.QueueProperties queueProperties, boolean ignoreExists, Object | String | null | undefined correlationKey ) | |
void | resetStats ( ) | |
void | send ( solace.Message message ) | |
void | sendReply ( solace.Message messageToReplyTo, solace.Message replyMessage ) | |
void | sendRequest ( solace.Message message, Number timeout, solace.Session.replyReceivedCallback replyReceivedCBFunction, solace.Session.requestFailedCallback requestFailedCBFunction, Object userObject ) | |
void | subscribe ( solace.Destination topic, Boolean requestConfirmation, Object | String | null | undefined correlationKey, Number | null | undefined requestTimeout ) | |
void | unsubscribe ( solace.Destination topic, Boolean requestConfirmation, Object | String | null | undefined correlationKey, Number | null | undefined requestTimeout ) | |
void | unsubscribeDurableTopicEndpoint ( solace.AbstractQueueDescriptor | solace.QueueDescriptor queueDescriptor ) | |
void | updateAuthenticationOnReconnect ( Object authenticationProperties ) | |
void | updateProperty ( MutableSessionProperty mutableSessionProperty, Object newValue, Number requestTimeout, Object | String | null | undefined correlationKey ) |
Constructor details
Top
Session
( )
This class is not exposed for construction by API users.
Applications must use solace.SolclientFactory.createSession to create a session.
Represents a client Session.
Session provides these major functions:
- Subscriber control, such as updating subscriptions;
- Publishes both Direct and Guaranteed Messages to the router;
- Receives direct messages from the router.
The Session object is an
EventEmitter, and will emit
events with event names from solace.SessionEventCode when Session events occur.
Each session event can be subscribed using solace.Session#on with the corresponding
solace.SessionEventCode. If any of the registered event listeners throw an exception,
the exception will be emitted on the 'error' event.
Fires
- solace.SessionEventCode#event:ACKNOWLEDGED_MESSAGE
- solace.SessionEventCode#event:CAN_ACCEPT_DATA
- solace.SessionEventCode#event:CONNECT_FAILED_ERROR
- solace.SessionEventCode#event:DISCONNECTED
- solace.SessionEventCode#event:DOWN_ERROR
- solace.SessionEventCode#event:GUARANTEED_MESSAGE_PUBLISHER_DOWN
- solace.SessionEventCode#event:MESSAGE
- solace.SessionEventCode#event:PROPERTY_UPDATE_ERROR
- solace.SessionEventCode#event:PROPERTY_UPDATE_OK
- solace.SessionEventCode#event:RECONNECTED_NOTICE
- solace.SessionEventCode#event:RECONNECTING_NOTICE
- solace.SessionEventCode#event:REJECTED_MESSAGE_ERROR
- solace.SessionEventCode#event:REPUBLISHING_UNACKED_MESSAGES
- solace.SessionEventCode#event:SUBSCRIPTION_ERROR
- solace.SessionEventCode#event:SUBSCRIPTION_OK
- solace.SessionEventCode#event:UNSUBSCRIBE_TE_TOPIC_ERROR
- solace.SessionEventCode#event:UNSUBSCRIBE_TE_TOPIC_OK
- solace.SessionEventCode#event:UP_NOTICE
- solace.SessionEventCode#event:VIRTUALROUTER_NAME_CHANGED
- solace.SessionEventCode#event:PROVISION_OK
- solace.SessionEventCode#event:PROVISION_ERROR
This class is not exposed for construction by API users. Applications must use solace.SolclientFactory.createSession to create a session.
Represents a client Session.
Session provides these major functions:
- Subscriber control, such as updating subscriptions;
- Publishes both Direct and Guaranteed Messages to the router;
- Receives direct messages from the router.
The Session object is an EventEmitter, and will emit events with event names from solace.SessionEventCode when Session events occur. Each session event can be subscribed using solace.Session#on with the corresponding solace.SessionEventCode. If any of the registered event listeners throw an exception, the exception will be emitted on the 'error' event.
Fires
- solace.SessionEventCode#event:ACKNOWLEDGED_MESSAGE
- solace.SessionEventCode#event:CAN_ACCEPT_DATA
- solace.SessionEventCode#event:CONNECT_FAILED_ERROR
- solace.SessionEventCode#event:DISCONNECTED
- solace.SessionEventCode#event:DOWN_ERROR
- solace.SessionEventCode#event:GUARANTEED_MESSAGE_PUBLISHER_DOWN
- solace.SessionEventCode#event:MESSAGE
- solace.SessionEventCode#event:PROPERTY_UPDATE_ERROR
- solace.SessionEventCode#event:PROPERTY_UPDATE_OK
- solace.SessionEventCode#event:RECONNECTED_NOTICE
- solace.SessionEventCode#event:RECONNECTING_NOTICE
- solace.SessionEventCode#event:REJECTED_MESSAGE_ERROR
- solace.SessionEventCode#event:REPUBLISHING_UNACKED_MESSAGES
- solace.SessionEventCode#event:SUBSCRIPTION_ERROR
- solace.SessionEventCode#event:SUBSCRIPTION_OK
- solace.SessionEventCode#event:UNSUBSCRIBE_TE_TOPIC_ERROR
- solace.SessionEventCode#event:UNSUBSCRIBE_TE_TOPIC_OK
- solace.SessionEventCode#event:UP_NOTICE
- solace.SessionEventCode#event:VIRTUALROUTER_NAME_CHANGED
- solace.SessionEventCode#event:PROVISION_OK
- solace.SessionEventCode#event:PROVISION_ERROR
Static Methods Detail Top
static
public
void
replyReceivedCallback
( solace.Session session, solace.Message message, Object userObject )
A callback that returns replies to requests sent via solace.Session#sendRequest. The replyReceivedCallback must be provided to the API as the third argument of solace.Session#sendRequest.
static
public
void
requestFailedCallback
( solace.Session session, solace.RequestError error, Object userObject )
A callback that returns errors associated with requests sent via solace.Session#sendRequest. The requestFailedCallback must be provided to the API as the fourth argument of solace.Session#sendRequest
Methods Detail Top
public
void
connect
( )
Connects the session to the Solace Message Router as configured in the solace.SessionProperties#url.
When the session is successfully connected to the Solace Message Router, the solace.SessionEventCode#UP_NOTICE event is emitted if a listener has been registered.
If solace.SessionProperties#reapplySubscriptions is set to true, this operation re-registers previously registered subscriptions. The connected session event (solace.SessionEventCode#event:UP_NOTICE) is emitted only when all the subscriptions are successfully added to the router.
If the API is unable to connect within solace.SessionProperties#connectTimeoutInMsecs or due to login failures, the session's state transitions back to 'disconnected' and an event is generated.
Note: Before the session's state transitions to 'connected', a client application cannot use the session; any attempt to call functions will throw solace.OperationError.
Creates a solace.CacheSession object that uses this Session to service its cache requests.
It should be disposed when the application no longer requires a CacheSession, by calling solace.CacheSession#dispose.
public
solace.MessageConsumer
createMessageConsumer
( solace.MessageConsumerProperties | Object consumerProperties )
Creates a solace.MessageConsumer to receive Guaranteed Messages in this Session.
Consumer characteristics and behavior are defined by properties. The consumer properties are supplied as an object; the pertinent fields are exposed in solace.MessageConsumerProperties; other property names are ignored. If the Message Consumer creation specifies a non-durable endpoint, solace.QueueProperties can be used to change the default properties on the non-durable endpoint. Any values not supplied are set to default values.
When the consumer is created, a consumer object is returned to the caller. This is the object from which events are emitted, and upon which operations (for example, starting and stopping the consumer) are performed.
If this session does not support Guaranteed Messaging, this method will throw. The Solace Messaging Router must support Guaranteed Messaging.
public
solace.QueueBrowser
createQueueBrowser
( solace.QueueBrowserProperties | Object browserProperties )
Creates a solace.QueueBrowser to receive Guaranteed Messages in this Session.
Browser characteristics and behavior are defined by properties. The properties are supplied as an object; the pertinent fields are exposed in solace.QueueBrowserProperties; other property names are ignored.
Delivery restrictions imposed by the queue’s Access type (exclusive or non-exclusive), do not apply when browsing messages with a Browser.
When the browser is created, a browser object is returned to the caller. This is the object from which events are emitted, and upon which operations (for example, starting and stopping the browser) are performed.
If this session does not support Guaranteed Messaging, this method will throw. The Solace Messaging Router must support Guaranteed Messaging.
public
void
deprovisionEndpoint
( solace.QueueDescriptor queueDescriptor, boolean ignoreMisssing, Object | String | null | undefined correlationKey )
Deprovisons a queue or topic endpoint on the broker. The function returns immediately (unless the parameters fail validation in which case an exception is thrown), but the actual outcome of the operation on the broker is only reported later in the form of a POVISION_OK or PROVISION_ERROR session event. Make sure to subscribe for those when using this fuction.
public
void
disconnect
( )
Disconnects the session. The session attempts to disconnect cleanly, concluding all operations in progress. The disconnected session event solace.SessionEventCode#event:DISCONNECTED is emitted when these operations complete and the session has completely disconnected.
public
void
dispose
( )
Release all resources associated with the session. It is recommended to call disconnect() first for proper handshake with the message-router.
Get the value of an router capability, or null if unknown. This function must be called after connecting the session.
SDT Type conversions:
- {string} values are returned as solace.SDTFieldType.STRING.
- {boolean} values are returned as solace.SDTFieldType.BOOL.
- All numeric values are returned as solace.SDTFieldType.INT64.
Returns a clone of the properties for this session.
Returns the value of a given solace.StatType.
public
String
getTransportInfo
( )
Gets a transport session information string. This string is informative only, and applications should not attempt to parse it.
Check the value of a boolean router capability.
This function is a shortcut for solace.Session#getCapability. It performs the same operation, but instead of returning a solace.SDTField wrapping a capability value, it just returns the boolean value.
Attempting to query a non-boolean capability will return null
.
public
void
provisionEndpoint
( solace.QueueDescriptor queueDescriptor, solace.QueueProperties queueProperties, boolean ignoreExists, Object | String | null | undefined correlationKey )
Provisons a queue or topic endpoint on the broker without binding a flow or adding a subscription. The function returns immediately (unless the parameters fail validation in which case an exception is thrown), but the actual outcome of the operation on the broker is only reported later in the form of a POVISION_OK or PROVISION_ERROR session event. Make sure to subscribe for those when using this fuction.
public
void
resetStats
( )
Reset session statistics to initial values.
Publish (send) a message over the session. The message is sent to its set destination.
This method is used for sending both direct and Guaranteed Messages. If the message's solace.MessageDeliveryModeType is solace.MessageDeliveryModeType.DIRECT, the message is a direct message; otherwise, it is a guaranteed message.
Sends a reply message to the destination specified in messageToReplyTo.
If messageToReplyTo
is non-null:
- solace.Message#getReplyTo is copied from
messageToReplyTo
to solace.Message#setDestination onreplyMessage
, unlessreplyTo
is null. - solace.Message#setCorrelationId is copied from
messageToReplyTo
to solace.Message#setCorrelationId onreplyMessage
, unlesscorrelationId
is null.
If messageToReplyTo
is null, the application is responsible for setting
the destination
and correlationId
on the replyMessage
.
public
void
sendRequest
( solace.Message message, Number timeout, solace.Session.replyReceivedCallback replyReceivedCBFunction, solace.Session.requestFailedCallback requestFailedCBFunction, Object userObject )
Sends a request using user-specified callback functions.
The API fills in the correlationId and replyTo fields in the request when they are not preset by the application. This is the preferred use case to ensure replies are directed back to the correct requester.
public
void
subscribe
( solace.Destination topic, Boolean requestConfirmation, Object | String | null | undefined correlationKey, Number | null | undefined requestTimeout )
Subscribe to a topic, optionally requesting a confirmation from the router.
If requestConfirmation is set to true: solace.SessionEventCode.SUBSCRIPTION_OK is generated when subscription is added successfully; otherwise, session event solace.SessionEventCode.SUBSCRIPTION_ERROR is generated.
If requestConfirmation is set to false, only session event solace.SessionEventCode.SUBSCRIPTION_ERROR is generated upon failure.
When the application receives session event
solace.SessionEventCode.SUBSCRIPTION_ERROR, it
can obtain the failed topic subscription by calling
solace.SessionEvent#reason.
The returned string is in the format of "Topic:
public
void
unsubscribe
( solace.Destination topic, Boolean requestConfirmation, Object | String | null | undefined correlationKey, Number | null | undefined requestTimeout )
Unsubscribe from a topic, and optionally request a confirmation from the router.
If requestConfirmation is set to true, session event solace.SessionEventCode.SUBSCRIPTION_OK is generated when subscription is removed successfully; otherwise, session event solace.SessionEventCode.SUBSCRIPTION_ERROR is generated.
If requestConfirmation is set to false, only session event solace.SessionEventCode.SUBSCRIPTION_ERROR is generated upon failure.
When the application receives session event
solace.SessionEventCode.SUBSCRIPTION_ERROR, it
can obtain the failed topic subscription by calling
solace.SessionEvent#reason. The returned
string is in the format "Topic:
public
void
unsubscribeDurableTopicEndpoint
( solace.AbstractQueueDescriptor | solace.QueueDescriptor queueDescriptor )
Request that a Durable Topic Endpoint stop receiving data on a topic. Unsubscribe requests are only allowed by the router when no clients are bound to the DTE. If the unubscribe request is successful, the DTE will stop attracting messages, and all messages spooled to the DTE will be deleted.
solace.SessionEventCode.UNSUBSCRIBE_TE_TOPIC_OK is generated when the subscription is removed successfully; otherwise, solace.SessionEventCode.UNSUBSCRIBE_TE_TOPIC_ERROR is generated.
When the application receives session event solace.SessionEventCode.UNSUBSCRIBE_TE_TOPIC_ERROR, it can obtain the failed topic subscription by calling solace.SessionEvent#reason.
public
void
updateAuthenticationOnReconnect
( Object authenticationProperties )
Modify (some) authentication-related session properties. The modifications take effect the next time the session connects or reconnects to the broker. There is no change to the active connection. Calling this method does not in itself trigger any kind of reconnection, reauthentication or renegotiation.
Note: the update of "accessToken" and "idToken" properties is currently supported. Authentication Properties
- accessToken to update previously set access token required for OAUTH2 authentication.
- idToken to update previously set ID token required for OIDC authentication Example: updateAuthenticationOnReconnect({accessToken : “my_new_token”});
public
void
updateProperty
( MutableSessionProperty mutableSessionProperty, Object newValue, Number requestTimeout, Object | String | null | undefined correlationKey )
Modify a session property after creation of the session.
This method only works for a select few properties, and updates their value on the live broker session.