public async Task RabbitMqBus_PublishSubscribe_Test() { var options = CreateOptions(); var logger = CommonUtils.CreateLogger <RabbitMqBus>(); var rabbitMqBus = new RabbitMqBus(options, logger); var rabbitMqListener = new RabbitMqListener(options, logger); var message = new TestMessage { Id = "1", String = "Test string", }; var count = 0; TestMessage result = null; rabbitMqListener.Subscribe("test", (TestMessage m) => { result = m; return(Task.FromResult(count++)); }, InteractionType.PublishSubscribe); var count2 = 0; TestMessage result2 = null; rabbitMqListener.Subscribe("test", (TestMessage m) => { result2 = m; return(Task.FromResult(count2++)); }, InteractionType.PublishSubscribe); await rabbitMqBus.Publish("test", message, InteractionType.PublishSubscribe); await rabbitMqBus.Publish("test", message, InteractionType.PublishSubscribe); await TimeSpan.FromSeconds(1) .StopOnCondition(TimeSpan.FromMilliseconds(100), () => count >= 2 && count2 >= 2); count.ShouldBe(2); result.ShouldNotBeNull(); result.Id.ShouldBe(message.Id); result.String.ShouldBe(message.String); count2.ShouldBe(2); result2.ShouldNotBeNull(); result2.Id.ShouldBe(message.Id); result2.String.ShouldBe(message.String); }
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 void SendDocument(Document document) { _bus.Publish(document); }