Initializing and Monitoring APIs
This section describes how to initialize the Solace Messaging API and provides information for using Solace Messaging API logging and session statistics.
Initializing APIs
To work with a Solace Messaging API, it must first be initialized.
Solace Messaging API for Java RTO, C, and .NET
Call a function or method listed in the table below to initialize the Solace Java RTO API, Solace C API, or Solace .NET API. When these Solace Messaging APIs are initialized, you can optionally set the initial log level filter for all log categories so that only logs at a specified level and more severe are emitted. (For more information on logging levels, see Configuring Logging.)
You can also set the global buffer sizes for the memory pools that are used to temporarily save messages in the application space (for the Solace Java RTO API, see Modifying the Global Pool Buffer Sizes; for the Solace C API, see Solace C API Best Practices; for the Solace .NET API, see Modifying the Global Pool Buffer Sizes).
Solace Messaging API for JavaScript and Node.js
Call the function listed in the table below to initialize the Solace JavaScript API and Solace Node.js API. By default, when these APIs are initialized, they include the version 7 behavior profile for backwards compatibility. Behavior profiles allow old applications to remain compatible with old versions of the API, while allowing new applications to take advantage of updated recommended defaults. When writing a new application, Solace recommends using the newest available profile. For example, if version 10 is the newest profile, add the following to the entry point of your application to initialize the API with the version 10 profile and run it with the default property values that Solace recommends at the time of the version 10 release:
var factoryProps = new solace.SolclientFactoryProperties(); factoryProps.profile = solace.SolclientFactoryProfiles.version10; solace.SolclientFactory.init(factoryProps);
When modifying an existing application to use a new behavior profile, the differences between behavior profiles should be considered.
| Solace Messaging API | Use |
|---|---|
|
Solace Java RTO API |
|
|
Solace C API |
|
|
Solace .NET API |
|
|
Solace JavaScript API and Solace Node.js API |
|
Related Samples
For an example of how to initialize the Solace Java RTO API or Solace C API, see the DirectPubSub sample for that API. For the Solace .NET API, see SampleApp. For the Solace JavaScript API and Solace Node.js API, see the TopicSubscriber and TopicPublisher samples.
Cleanup
When the client application is finished using the Solace C API or Solace .NET API, it should perform a global clean-up, which automatically frees all allocated resources, including those allocated for contexts and sessions that have been previously created but are not destroyed.
| Solace Messaging API | Use |
|---|---|
|
Solace JCSMP API |
Not applicable |
|
Solace Java RTO API |
Not applicable |
|
Solace C API |
|
|
Solace .NET API |
|
|
Solace JavaScript API and Solace Node.js API |
Not applicable |
- Contexts and sessions should always be destroyed or disposed before a cleanup is performed. If
solClient_cleanup()orContextFactory.Cleanup()is called while sessions are connected, any messages buffered for transmission are discarded and not sent.Note that invocations of “initialize” and “cleanup” are reference counted. For example, if “initialize” is called twice, “cleanup” must be called twice to properly free the resources.
- In the .NET environment, the .NET garbage collector may attempt to release
IMessagecontainers after the application has calledContextFactory.Cleanup(). This will cause warnings like “2012-08-07 19:11:50Z - Warn - Sdk:Bad msg_p pointer (0000000004000FE1) in solClient_msg_free”. These warnings may be disregarded because they indicate that the API has detected and avoided a double-free.
However, if the same application callsContextFactory.Init()subsequent toContextFactory.Cleanup(), the garbage collector may release messages that have been re-assigned to the newly initializedContextFactory, and this will lead to an application crash. Therefore, it is recommended that you only callContextFactory.Init()/ContextFactory.Cleanup()once.
Related Samples
For an example of how to perform a global cleanup for the Solace C API, see the DirectPubSub sample. For the Solace .NET API, see SampleUtils.cs included with the sample files.