//TODO Connection Cleanup on Unsubscribe/failure/etc //TODO General Error handling -> OnError static async Task Main(string[] args) { var loopback = new LoopbackTransport(); var server = new EchoServer(loopback.Beyond); await server.ConnectAsync(); //var client = new RSocketClient(new SocketTransport("tcp://localhost:9091/"), new RSocketOptions() { InitialRequestSize = 3 }); //var client = new RSocketClient(new WebSocketTransport("ws://localhost:9092/"), new RSocketOptions() { InitialRequestSize = 3 }); var client = new RSocketClient(loopback, new RSocketOptions() { InitialRequestSize = int.MaxValue }); await client.ConnectAsync(); Console.WriteLine("Requesting Raw Protobuf Stream..."); var persondata = new Person() { Id = 1234, Name = "Someone Person", Address = new Address() { Line1 = "123 Any Street", Line2 = "Somewhere, LOC" } }; var personmetadata = new Person() { Id = 567, Name = "Meta Person", Address = new Address() { Line1 = "", Line2 = "" } }; //Make a Raw binary call just to show how it's done. //var stream = client.RequestStream( // resultmapper: result => (Data: ProtobufNetSerializer.Deserialize<Person>(result.Data), Metadata: ProtobufNetSerializer.Deserialize<Person>(result.Metadata)), // data: ProtobufNetSerializer.Serialize(persondata), metadata: ProtobufNetSerializer.Serialize(personmetadata)); var stream = client.RequestStream(ProtobufNetSerializer.Serialize(persondata), ProtobufNetSerializer.Serialize(personmetadata)); await stream.ForEachAsync(persons => Console.WriteLine($"RawDemo.OnNext===>[{ProtobufNetSerializer.Deserialize<Person>(persons.Metadata)}]{ProtobufNetSerializer.Deserialize<Person>(persons.Data)}")); Console.WriteLine("\nRequesting String Serializer Stream..."); await client.RequestStream("A Demo Payload") .ForEachAsync(result => Console.WriteLine($"StringDemo.OnNext===>{result}")); Console.ReadKey(); //var sender = from index in Observable.Interval(TimeSpan.FromSeconds(1)) select new Person() { Id = (int)index, Name = $"Person #{index:0000}" }; //using (personclient.RequestChannel(obj).Subscribe( // onNext: value => Console.WriteLine($"RequestChannel.OnNext ===>{value}"), onCompleted: () => Console.WriteLine($"RequestChannel.OnComplete!"))) //{ // Console.ReadKey(); //} }
//TODO Connection Cleanup on Unsubscribe/failure/etc //TODO General Error handling -> OnError static async Task Main(string[] args) { //var client = new RSocketClient(new RSocketWebSocketClient("ws://rsocket-demo.herokuapp.com/ws")); //await client.RequestStream("peace", initial: 2); //var client = new RSocketClient(new RSocketWebSocketClient("ws://localhost:9092/")); var loopback = new LoopbackTransport(); var server = new RSocketServer(loopback); server.Start(); var client = new RSocketClientReactive( new WebSocketTransport("ws://localhost:9092/")) //new SocketTransport("tcp://localhost:9092/")) //var client = new RSocketClientReactive(new RSocketWebSocketClient("ws://localhost:9092/")) //var client = new RSocketClientReactive(loopback) .UsingProtobufNetSerialization(); await client.ConnectAsync(); Console.WriteLine("Requesting Demo Stream..."); var obj = new Person() { Id = 1234, Name = "Someone Person", Address = new Address() { Line1 = "123 Any Street", Line2 = "Somewhere, LOC" } }; var meta = new Person() { Id = 567, Name = "Meta Person", Address = new Address() { Line1 = "", Line2 = "" } }; var req = new ProtobufNetSerializer().Serialize(obj).ToArray(); // Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(obj)); //TODO req is awkward here, probably need to have incoming and return types... //var rr = client.RequestStream<Person, Person, Person, Person>(data: obj); var personclient = client.Of <Person, Person>(); var stream = from data in personclient.RequestStream(obj, meta, initial: 3) //where value.StartsWith("q") select data.Data; using (stream.Subscribe( onNext: value => Console.WriteLine($"Demo.OnNext===>{value}"), onCompleted: () => Console.WriteLine($"Demo.OnComplete!\n"))) using (personclient.RequestChannel(obj).Subscribe( onNext: value => Console.WriteLine($"RequestChannel.OnNext ===>{value}"), onCompleted: () => Console.WriteLine($"RequestChannel.OnComplete!\n"))) using (personclient.RequestStream(obj).Subscribe( onNext: value => Console.WriteLine($"RequestStream.OnNext ===>{value}"), onCompleted: () => Console.WriteLine($"RequestStream.OnComplete!\n"))) using (personclient.RequestResponse(obj).Subscribe( onNext: value => Console.WriteLine($"RequestResponse.OnNext ===>{value}"), onCompleted: () => Console.WriteLine($"RequestResponse.OnComplete!\n"))) using (personclient.RequestFireAndForget(obj).Subscribe( onNext: value => Console.WriteLine($"RequestFireAndForget.OnNext ===>{value}"), onCompleted: () => Console.WriteLine($"RequestFireAndForget.OnComplete!\n"))) { Console.ReadKey(); } //var sender = from index in Observable.Interval(TimeSpan.FromSeconds(1)) select new Person() { Id = (int)index, Name = $"Person #{index:0000}" }; //using (personclient.RequestChannel(obj).Subscribe( // onNext: value => Console.WriteLine($"RequestChannel.OnNext ===>{value}"), onCompleted: () => Console.WriteLine($"RequestChannel.OnComplete!"))) //{ // Console.ReadKey(); //} }