public void CanSubscribeToChannelAndReceiveMessagePublishedToIt() { var subscriber = ConnectionMultiplexer.GetSubscriber(); RedisChannel receivedChannel = default(RedisChannel); RedisValue receivedValue = default(RedisValue); var receivedEvent = new ManualResetEvent(false); subscriber.Subscribe("channel", (channel, value) => { receivedChannel = channel; receivedValue = value; receivedEvent.Set(); }); Database.Publish("channel", "Hello"); receivedEvent.WaitOne(TimeSpan.FromSeconds(5)).Should().BeTrue(); receivedChannel.Should().Be("channel"); receivedValue.Should().Be("Hello"); }
public void WhenMultipleSubscribersExistTheyEachReceivePublishedMessage() { var subscriber1 = ConnectionMultiplexer.GetSubscriber(); var subscriber2 = ConnectionMultiplexer.GetSubscriber(); RedisChannel receivedChannel1 = default(RedisChannel); RedisChannel receivedChannel2 = default(RedisChannel); RedisValue receivedValue1 = default(RedisValue); RedisValue receivedValue2 = default(RedisValue); var receivedEvent1 = new ManualResetEvent(false); var receivedEvent2 = new ManualResetEvent(false); subscriber1.Subscribe("channel", (channel, value) => { receivedChannel1 = channel; receivedValue1 = value; receivedEvent1.Set(); }); subscriber2.Subscribe("channel", (channel, value) => { receivedChannel2 = channel; receivedValue2 = value; receivedEvent2.Set(); }); Database.Publish("channel", "Hello"); WaitHandle.WaitAll(new[] { receivedEvent1, receivedEvent2 }, TimeSpan.FromSeconds(5)) .Should() .BeTrue(); receivedChannel1.Should().Be("channel"); receivedChannel2.Should().Be("channel"); receivedValue1.Should().Be("Hello"); receivedValue2.Should().Be("Hello"); }