public async Task CanPublishAndReceiveMultipleMessagesOnChannel() { var expected = "CanPublishAndReceiveOnChannel"; using (var socketConnection = new SocketConnection(TestsSetup.Host, TestsSetup.Port, Scheduler.Immediate)) { using (var publisherConnection = new SocketConnection(TestsSetup.Host, TestsSetup.Port, Scheduler.Immediate)) { var subscriber = socketConnection.AsSubscriber(); var publisher = publisherConnection.AsPublisher(); var matchedReplies = 0; var tcs = new TaskCompletionSource<bool>(); var expectedMessagesCount = 512; var messagesChannel = await subscriber.Subscribe("channel1"); messagesChannel.Subscribe(message => { if (string.Compare(message.Content, expected, StringComparison.InvariantCultureIgnoreCase) == 0) matchedReplies += 1; if (matchedReplies == expectedMessagesCount) tcs.SetResult(true); }); foreach (var once in Enumerable.Repeat(Unit.Default, expectedMessagesCount)) { var result = await publisher.PublishMessage("channel1", expected); } await Task.WhenAny(Task.Delay(1000), tcs.Task); Assert.AreEqual(expectedMessagesCount, matchedReplies); } } }
async void buttonSendMessage_Click(object sender, RoutedEventArgs e) { try { using (var connection = new SocketConnection("127.0.0.1", 4525, Scheduler.Immediate)) { var publisher = connection.AsPublisher(); await publisher.PublishMessage("alert1", textBoxMessage.Text); //await publisher.PublishMessage("alert2", textBoxMessage.Text); } using (var connection = new SocketConnection("127.0.0.1", 4525, Scheduler.Immediate)) { var cacheClient = connection.AsCacheClient(); //await cacheClient.SetValue("alert1", textBoxMessage.Text); var result = await cacheClient.GetValues(new string[]{"alert1", "alert3"}); await cacheClient.Del("alert1"); var result2 = await cacheClient.GetValues(new string[] { "alert1", "alert3" }); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public async Task CanPublishAndReceiveOnChannel() { var expected = "CanPublishAndReceiveOnChannel"; using (var socketConnection = new SocketConnection(TestsSetup.Host, TestsSetup.Port, Scheduler.Immediate)) { using (var publisherConnection = new SocketConnection(TestsSetup.Host, TestsSetup.Port, Scheduler.Immediate)) { var subscriber = socketConnection.AsSubscriber(); var publisher = publisherConnection.AsPublisher(); var messagesChannel = await subscriber.Subscribe("channel1"); var replaySubject = new ReplaySubject<string>(); messagesChannel.Take(1).Select(x => x.Content).Subscribe(replaySubject); await publisher.PublishMessage("channel1", expected); var result = await replaySubject.FirstAsync(); Assert.AreEqual(expected, result); } } }