protected override async Task RunAsync(IWampChannel channel) { await channel.Open().ConfigureAwait(false); await Task.Yield(); IWampSubject topic = channel.RealmProxy.Services.GetSubject("com.myapp.topic1"); using (IDisposable disposable = topic.Subscribe(value => Console.WriteLine($"Got event, publication ID {value.PublicationId}, publisher {value.Details.Publisher}: {value.Arguments[0].Deserialize<int>()}"), ex => Console.WriteLine($"An error has occurred {ex}"))) { Console.WriteLine("Hit enter to unsubscribe"); Console.ReadLine(); } Console.WriteLine("Unsubscribed"); Console.ReadLine(); }
protected override async Task RunAsync(IWampChannel channel) { await channel.Open().ConfigureAwait(false); await Task.Yield(); IWampSubject heartbeatSubject = channel.RealmProxy.Services.GetSubject("com.myapp.heartbeat"); var topic2Subject = channel.RealmProxy.Services.GetSubject("com.myapp.topic2", new Topic2TupleConverter()); using (IDisposable heartbeatDisposable = heartbeatSubject.Subscribe(value => Console.WriteLine($"Got heartbeat (publication ID {value.PublicationId})"), ex => Console.WriteLine($"An error has occurred {ex}"))) { void Topic2EventHandler((int number1, int number2, string c, MyClass d) value) { (int number1, int number2, string c, MyClass d) = value; Console.WriteLine($@"Got event: number1:{number1}, number2:{number2}, c:""{c}"", d:{{{d}}}"); } void Topic2ErrorHandler(Exception exception) { Console.WriteLine($"An error has occurred {exception}"); } using (IDisposable topic2Disposable = topic2Subject.Subscribe(Topic2EventHandler, Topic2ErrorHandler)) { Console.WriteLine("Hit enter to unsubscribe"); Console.ReadLine(); } } Console.WriteLine("Unsubscribed"); Console.ReadLine(); }