Remove a publisher
- Last UpdatedApr 08, 2026
- 1 minute read
This scenario guides you through the steps required to remove a publisher.
To identify the code associated with each step, see the code comments in the Example code section.
To remove a publisher
- 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.
- Remove this application as a publisher by using one of the following methods:
- Using the RemovePublisher method.
// Remove this application as a publisher. pubsubConnection.RemovePublisher(topic); - Once the using block is finished, disposing the connection will remove the publisher, clean up, and disconnect from the engine. If a using block is used, calling Disconnect explicity is optional.
Example code
internal void RemovePublisher()
{
try
{
IPubSubConnectionFactory pubSubConnectionFactory = new PubSubConnectionFactory();
// Open a PubSub connection.
using (var pubsubConnection = pubSubConnectionFactory.OpenConnection())
{
// Confirm there is a connection with the PubSub system.
if (pubsubConnection.IsConnected())
{
var topic = "es.realtime.db.analog.DeviceRollupAnalog01.curval";
var pubSubMessage = new PubSubMessageBuilder(topic, PubSubHeaderData.PS_NORMAL_DATA).Write(24.5).GetResult();
// Publish data on a topic.
pubsubConnection.Publish(pubSubMessage);
// Remove this application as a publisher.
pubsubConnection.RemovePublisher(topic);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error:" + ex.Message);
}
}