public async Task RepeatSecondMessage() { var channel = GenerateRandomChannelName(); var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build(); var obs = new SubscriptionObserver(); var subData = obs.CreateSubscriptionDataQueue(); client.Start(); await client.CreateSubscriptionAndWaitSubscribed(channel, null, obs); await client.Publish(channel, "first-message", Ack.Yes).ConfigureAwait(false); var pos = (await subData.DequeueAndVerify(channel, "first-message").ConfigureAwait(false)).Position; await client.Publish(channel, "second-message", Ack.Yes).ConfigureAwait(false); await subData.DequeueAndVerify(channel, "second-message").ConfigureAwait(false); client.RemoveSubscription(channel); await client.CreateSubscriptionAndWaitSubscribed(channel, pos, obs).ConfigureAwait(false); await subData.DequeueAndVerify(channel, "second-message").ConfigureAwait(false); client.RemoveSubscription(channel); client.Stop(); await client.Dispose(); }
public async Task RepeatFirstMessage() { var channel = GenerateRandomChannelName(); var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build(); await client.Yield(); var subObs = new SubscriptionObserver(); var subData = subObs.CreateSubscriptionDataQueue(); var subscription = new QueueAsync <string>(); subObs.OnEnterSubscribed += s => { subscription.Enqueue(s.Position); }; client.Start(); client.CreateSubscription(channel, SubscriptionModes.Advanced, subObs); var pos = await subscription.Dequeue().ConfigureAwait(false); await client.Publish(channel, "message-1", Ack.Yes).ConfigureAwait(false); await subData.DequeueAndVerify(channel, "message-1").ConfigureAwait(false); await client.Yield(); client.RemoveSubscription(channel); client.CreateSubscription( channel, new SubscriptionConfig(SubscriptionModes.Advanced, position: pos, observer: subObs)); await subData.DequeueAndVerify(channel, "message-1").ConfigureAwait(false); await client.Dispose(); }
public async Task TwoClients() { var channel = GenerateRandomChannelName(); int i = 0; var msg = $"message-{i++}"; var subscriber = (RtmClient) new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build(); var publisher = new RtmClientBuilder(Config.Endpoint, Config.AppKey).Build(); publisher.Start(); subscriber.Start(); var subObs = new SubscriptionObserver(); var subData = subObs.CreateSubscriptionDataQueue(); await subscriber.CreateSubscriptionAndWaitSubscribed(channel, null, subObs).ConfigureAwait(false); await publisher.Publish(channel, msg, Ack.Yes).ConfigureAwait(false); await subData.DequeueAndVerify(channel, msg).ConfigureAwait(false); subscriber.Stop(); if ((await subscriber.GetStateAsync()).GetConnection() != null) { throw new Exception("test failed"); } do { msg = $"message-{i++}"; await publisher.Publish(channel, msg, Ack.Yes).ConfigureAwait(false); await Task.Delay(500); RtmSubscriptionData data; if (subData.TryDequeue(out data)) { throw new Exception("test failed"); } subscriber.Start(); await subData.DequeueAndVerify(channel, msg).ConfigureAwait(false); subscriber.Stop(); GC.Collect(); } while (i < 3); await subscriber.Dispose(); publisher.Stop(); await publisher.Dispose(); }