Subscribe with a global connection
- Last UpdatedApr 08, 2026
- 1 minute read
This scenario guides you through the steps required to subscribe with a global connection.
To identify the code associated with each step, see the code comments in the Example code section.
To subscribe with a global connection
- Open the Program.cs file from the created project.
- Connect to a global PubSub connection.
- Confirm there is a connection with the PubSub system.
- Subscribe to a PubSub topic.
Example code
internal void AddSubscriptionWithGlobalPubSubConnection()
{
try
{
// Connect to a global PubSub connection.
IGlobalPubSubConnectionAccessor globalPubSubConnection = new GlobalPubSubConnectionAccessor();
var sharedPubsubConnection = globalPubSubConnection.GlobalConnection;
// Confirm there is a connection with the PubSub system.
if (sharedPubsubConnection.IsConnected())
{
var topic = "es.realtime.db.analog.DeviceRollupAnalog01.curval";
// Subscribe to a PubSub topic.
var subscription = sharedPubsubConnection.Subscribe(topic);
}
}
catch (Exception ex)
{
Console.WriteLine("Error:" + ex.Message);
}
}