public void Subscribe() { Assert.Equal(ConnState.CONNECTED, connection.NATSConnection.State); StanMsg <Person> received = null; using (var subscription = connection.Subscribe <Person>("subject", (sender, args) => { received = args.Msg; received.Ack(); })) { var jack = new Person() { Id = 1, Name = "Jack", Age = 10, Data = new byte[] { 0, 1, 2, 3, 4 } }; connection.Publish("subject", jack); NeonHelper.WaitFor(() => received != null, TimeSpan.FromSeconds(5)); Assert.True(received.Data == jack); } }
public void WhenPublishingAllSubscribedObserversShouldGetTheMessage() { sync = TestSync.FourActors(); var subject = "008f9155d7b84821a26d2e41f73a9a7f"; var payload = SamplePayload.Random(); using (Context.StartStreamingServerWithEmbedded(Context.Server1)) { using (var cn = Context.GetStanConnection(Context.Server1)) { using (var observable = cn.Observe(subject)) { var interceptingOb = new TestObserver(_ => sync.SignalComplete()); var interceptingSafeOb = new TestObserver(_ => sync.SignalComplete()); StanMsg delegatingObIntercept = null, safeDelegatingObIntercept = null; observable.Subscribe(interceptingOb); observable.SubscribeSafe(interceptingSafeOb); observable.Subscribe(msg => { delegatingObIntercept = msg; sync.SignalComplete(); }); observable.SubscribeSafe(msg => { safeDelegatingObIntercept = msg; sync.SignalComplete(); }); cn.Publish(subject, payload); sync.WaitForAll(); Assert.Equal(payload, interceptingOb.OnNextResults.Single()); Assert.Equal(payload, interceptingSafeOb.OnNextResults.Single()); Assert.Equal(payload, delegatingObIntercept); Assert.Equal(payload, safeDelegatingObIntercept); } } } }