Creating Client Sessions

A session creates a single, client connection to a Solace event broker for sending and receiving messages. The Solace Message Format (SMF) is used to facilitate the communication between a client and an event broker, and this SMF communication is then encapsulated through a single TCP connection.

By default, sessions are unsecured—in a connected session, the SMF data sent between a client and an event broker is transmitted as plain text. However, it is also possible to establish a secure session that uses Transport Layer Security (TLS)/ Secure Sockets Layer (SSL) protocols so that the SMF data is encrypted. For information on how to configure specific TLS/SSL session properties and establish a secure session, see Creating Secure Sessions.

Sessions are always created within a context. The client application controls whether one or multiple sessions are grouped under a processing context. Once a session is created within a given context, it remains associated with that single context until it is disposed.

To create a session, the client application must provide the following:

  • Session properties

    Properties used to customize the session. Any session property that is not explicitly supplied is set to default values. Although the defaults can be used in many cases, some client and event broker parameters require specific input from the client to establish a connection to a Message VPN on an event broker. See Session Properties Required to Establish a Connection.

  • Session event delegate

    In the Solace .NET API, a session event delegate must be specified when creating a session. This delegate is invoked for each session event. See Creating Client Sessions.

  • Message receive delegate

    In the Solace .NET API, a message event delegate must be specified when creating a session. This delegate is invoked each time a Direct message is received through the session. See Receiving Direct Messages.

Once a session is created, it must be connected.

To Create a Session

In the Solace .NET API, use:

IContext.CreateSession(...)

To Connect a Session

In the Solace .NET API, use:

ISession.Connect()

To Close a Session

In the Solace .NET API, use:

  • ISession.Disconnect()

  • ISession.Dispose()

Disposing of the session is not required.

  • When using the Solace .NET API, calling Dispose() to destroy a session object is not required. If the session object is not destroyed, you may reconnect to it at a later time.
  • If a session is disposed or a global cleanup is performed, any buffered messages associated with that session are discarded before it is disconnected. When a context is disposed, the buffered messages associated with every session contained within that context are discarded.

Handling Session Events

When a session is created, the application must provide a session event delegate (EventHandler<SessionEventArgs>) that is invoked each time an event occurs over the session.

For a complete list of session events, see the Solace Messaging API for .NET reference.

Related Samples

  • For an example of how to create and connect sessions, see the DirectPubSub sample for the Solace .NET API.
  • For an example of how to configure a session event delegate for the Solace .NET API, see SampleUtils.cs included with the sample files.