Publish data into a PubSub topic
- Last UpdatedApr 08, 2026
- 1 minute read
This scenario guides you through the steps required to publish data into a PubSub topic.
To identify the code associated with each step, see the code comments in the Example code section.
To publish data into a PubSub topic
- Open the Program.cs file from the created project.
- Open a PubSub connection.
- Confirm there is a connection with the PubSub system.
- Publish data on a topic.
Example code
internal void Publish()
{
try
{
IPubSubConnectionFactory pubSubConnectionFactory = new PubSubConnectionFactory();
// Open a PubSub connection.
using (var pubsubConnection = pubSubConnectionFactory.OpenConnection())
{
// Confirm there is connection with the PubSub system.
if (pubsubConnection.IsConnected())
{
var topic = "es.realtime.db.analog.DeviceRollupAnalog01.curval";
// Publish data on a topic.
var pubSubMessage = new PubSubMessageBuilder(topic, PubSubHeaderData.PS_NORMAL_DATA).Write(25.5).GetResult();
pubsubConnection.Publish(pubSubMessage);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error:" + ex.Message);
}
}