public static void Main( string[] args ) { // Connect using a principal with 'modify_topic' and 'update_topic' permissions var session = Diffusion.Sessions.Principal( "control" ).Password( "password" ).Open( "ws://localhost:8080" ); // Get the TopicControl and TopicUpdateControl features var topicControl = session.GetTopicControlFeature(); var updateControl = session.GetTopicUpdateControlFeature(); // Create a single-value topic 'foo/counter' var topic = "foo/counter"; var addCallback = new AddCallback(); topicControl.AddTopic( topic, TopicType.SINGLE_VALUE, addCallback ); // Wait for the OnTopicAdded callback, or a failure if ( !addCallback.Wait( TimeSpan.FromSeconds( 5 ) ) ) { Console.WriteLine( "Callback not received within timeout." ); return; } else if ( addCallback.Error != null ) { Console.WriteLine( "Error : {0}", addCallback.Error.ToString() ); return; } var updateCallback = new UpdateCallback( topic ); // Update the topic for 16 minutes for ( var i = 0; i < 1000; ++i ) { updateControl.Updater.Update( topic, i.ToString(), updateCallback ); Thread.Sleep( 1000 ); } // Close session session.Close(); }
public static void Main(string[] args) { // Connect using a principal with 'modify_topic' and 'update_topic' permissions var session = Diffusion.Sessions.Principal("control").Password("password").Open("ws://localhost:8080"); // Get the TopicControl and TopicUpdateControl features var topicControl = session.GetTopicControlFeature(); var updateControl = session.GetTopicUpdateControlFeature(); // Create a single-value topic 'foo/counter' var topic = "foo/counter"; var addCallback = new AddCallback(); topicControl.AddTopic(topic, TopicType.SINGLE_VALUE, addCallback); // Wait for the OnTopicAdded callback, or a failure if (!addCallback.Wait(TimeSpan.FromSeconds(5))) { Console.WriteLine("Callback not received within timeout."); return; } else if (addCallback.Error != null) { Console.WriteLine("Error : {0}", addCallback.Error.ToString()); return; } var updateCallback = new UpdateCallback(topic); // Update the topic for 16 minutes for (var i = 0; i < 1000; ++i) { updateControl.Updater.Update(topic, i.ToString(), updateCallback); Thread.Sleep(1000); } // Close session session.Close(); }