public async Task ListenerFactory_SubscribeExtension_Test() { var options = CreateOptions(); var logger = CommonUtils.CreateLogger <RabbitMqBus>(); var rabbitMqBus = new RabbitMqBus(options, logger); var listenerFactory = new RabbitMqListenerFactory(options, CommonUtils.CreateLogger <RabbitMqListenerFactory>()); var count = 0; await listenerFactory.Create() .Subscribe("test", (string m) => Task.FromResult(Interlocked.Increment(ref count)), InteractionType.PublishSubscribe) .Subscribe("test", (string m) => Task.FromResult(Interlocked.Increment(ref count)), InteractionType.PublishSubscribe); await rabbitMqBus.Publish("test", "1", InteractionType.PublishSubscribe); await TimeSpan.FromSeconds(1) .StopOnCondition(TimeSpan.FromMilliseconds(100), () => count >= 2); count.ShouldBe(2); }
public async Task ListenerFactory_Test() { var options = CreateOptions(); var logger = CommonUtils.CreateLogger <RabbitMqBus>(); var rabbitMqBus = new RabbitMqBus(options, logger); var listenerFactory = new RabbitMqListenerFactory(options, CommonUtils.CreateLogger <RabbitMqListenerFactory>()); var rabbitMqListener = await listenerFactory.Create(); rabbitMqListener.ShouldNotBeNull(); var count = 0; rabbitMqListener.Subscribe("test", (string m) => Task.FromResult(count++), InteractionType.CompetingConsumers); await rabbitMqBus.Publish("test", "1", InteractionType.CompetingConsumers); await TimeSpan.FromSeconds(1) .StopOnCondition(TimeSpan.FromMilliseconds(100), () => count > 0); count.ShouldBe(1); }
public async Task ListenerFactory_WaitAndDispose_Test() { var options = CreateOptions(new RabbitMqOptions() { HostName = "http://unknown999", Port = 111, UserName = "******", Password = "******" }); var logger = CommonUtils.CreateLogger <RabbitMqBus>(); var listenerFactory = new RabbitMqListenerFactory(options, CommonUtils.CreateLogger <RabbitMqListenerFactory>()); var t = listenerFactory.Create(); await Task.WhenAny(t, Task.Delay(1000)); t.IsCompleted.ShouldBeFalse(); listenerFactory.Dispose(); await Task.WhenAny(t, Task.Delay(1000)); t.IsCanceled.ShouldBeTrue(); }