ThingWorx Edge .NET SDK Reference > .NET SDK ClientConfigurator: Offline Message Store
.NET SDK ClientConfigurator: Offline Message Store
Offline message storage is a queue that preserves messages that have not been sent in case the connection to the ThingWorx Platform is lost (for whatever reason) or the duty cycle is in the “off” state. By default, this feature is enabled. To learn how offline message store works at run time, continue to the next section. For information about the properties for this feature, refer to Properties for Offline Message Store. Finally, for troubleshooting information, refer to Troubleshooting the Offline Message Store.
How Offline Message Store Works
If devices lose their connection to the ThingWorx Platform or if their duty cycle is in the "off" state, outtgoing request messages are placed in the queue for later delivery. Queued messages are persisted in a file in the directory defined by the property, OfflineMsgStoreDir of the ClientConfigurator. The size limit is set by the property, OfflineMsgQueueSize. When the limit is reached, any subsequent attempt to queue more messages fails, with the new messages being lost. When connectivity is re-established, all the messages in this queue are sent to the ThingWorx Platform. Note that these original messages will likely time out while they are waiting for a response from the ThingWorx Platform. As a result, you do not receive any indication or confirmation that these messages were successfully processed by the platform. The property, ThrowOnOfflineMesssageSave, can be set to true to have an exception generated when messages are saved to offline storage, and this option is set to false by default.
Properties for the Offline Message Store
The following properties are available on the ClientConfigurator class for the offline message store:
OfflineMsgQueueSize(String value) — The maximum size, in bytes, of the queue where messages are stored while the machine/device is offline.
OfflineMsgStoreDir(String value) — Directory on the local machine/device where messages are stored (in files) when the system is offline.
ThrowOnOfflineMesssageSave — When in a disconnected state, outgoing messages are automatically saved to offline storage (if enabled) for delivery upon next connection. Set this property to true to have an exception thrown when messages are saved offline.
Troubleshooting the Offline Message Store
If the offline_msgs.bin file is always 0KB when a client is disconnected from ThingWorx Composer, you need to change how you disconnect the client from the server. Instead of preventing the client from reconnecting to the server, disconnect the server from the network. In addition, note that if a client is not generating new data while offline, nothing will be written to the offline message store.
Taken from the example SteamSensorClient.cs file, the following code snippet checks client.IsConnected(). As soon as the client disconnects, this function returns false:
{{ while (!client.isShutdown())
{
// Only process the Virtual Things if the client is connected
if (client.isConnected())
{
// Loop over all the Virtual Things and process them
foreach (VirtualThing thing in client.getThings().Values)
{
try
{ thing.processScanRequest(); //Console.WriteLine(this.isEnabled());
//Console.WriteLine("isEnabled property: " + this._isEnabled);
//client.invokeService(com.thingworx.relationships.RelationshipTypes.ThingworxEntityTypes.Things,
"MeghanThing", "testThing", vc, 30000); }
catch (Exception eProcessing)
{ Console.WriteLine("Error Processing Scan Request for [" + thing.getName() + "] :
" + eProcessing.Message); }
}
}
// Suspend processing at the scan rate interval
Thread.Sleep(scanRate);
}
}}
Was this helpful?