Handling Session Events

JCSMP

  • Session events

    An application can register an implementation of the SessionEventHandler interface when creating a session through JCSMPFactory#createSession(JCSMPProperties, Context, SessionEventHandler). This handler receives callbacks for session events defined in SessionEvent.

  • Channel reconnect events

    An application that uses the session’s default message consumer (acquired through JCSMPSession#getMessageConsumer()), can register a JCSMPReconnectEventHandler instance when acquiring that consumer. This handler receives callbacks before and after the client’s TCP connection is reconnected after a connection failure.

Java RTO API

An application can register a SessionEventCallback when creating a session with ContextHandle.createSessionForHandle(...).

For high-performance implementations of the Java RTO API, applications should use SessionHandle.getSessionEvent(...) rather than SessionHandle.takeSessionEvent(...). When a get is used, the API retains responsibility for the event and will destroy it at the appropriate time. When a take is used, the API gives up control of the event and it is up to the application to destroy it.

For more information on using getSessionEvent() and takeSessionEvent(), see Get vs. Take in Java RTO API Best Practices.

C API

When a session is created, the application must provide a session event callback (solClient_session_eventCallbackInfoFunc_t), along with an optional pointer to client data. This callback routine is invoked for event broker events that occur for the session, such as connection problems, or publish or subscription issues.

For a complete list of possible session events,see the PubSub+ Messaging API C reference.

.NET API

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 PubSub+ Messaging API .NET reference.

JavaScript and Node.js APIs

When a session is created, the application must provide session event listeners for each important session events that are invoked each time an event occurs over the session.

For a complete list of session events, see solace.SessionEventCode in the JavaScript and Node.js API reference.

Related Samples

  • For an example of how to configure a session event handler for JCSMP, see SampleUtils.java included with the sample files.
  • For an example of how to configure a session event callback for the Java RTO API, see SampleUtils.java included with the sample files.
  • For an example of how to configure a session event callback for the C API, see the common.c sample file.
  • For an example of how to configure a session event delegate for the .NET API, see SampleUtils.cs included with the sample files.
  • For an example of how to configure session event listeners for the JavaScript and Node.js APIs, see the TopicSubscriber.js sample.