public async Task ReceiveOnSubscribe_WHEN_SubscriberQueueDeleted_THEN_ItRecreates_SubscriberQueue_AND_ReceivesPublishedData()
        {
            const string message = "Test-Message-123";

            using (var receivedEvent = new ManualResetEvent(false))
            {
                using (var publisher = StartBus(_publisherQueueName))
                {
                    async Task HandlerMethod(string data)
                    {
                        if (string.Equals(data, message))
                        {
                            receivedEvent.Set();
                        }
                    }

                    using (var subscriber = StartBus(_subscriberQueueName, HandlerMethod))
                    {
                        await subscriber.Subscribe <string>();

                        // remove the input queue
                        RabbitMqTransportFactory.DeleteQueue(_subscriberQueueName);

                        // wait a short while
                        await Task.Delay(TimeSpan.FromSeconds(60));

                        // check that published message is received without problems
                        await publisher.Publish(message);

                        receivedEvent.WaitOrDie(TimeSpan.FromSeconds(2),
                                                "The event has not been receved by the subscriber within the expected time");
                    }
                }
            }
        }
Esempio n. 2
0
        public void Test_CreateQueue_WHEN_InputQueueOptions_SetQueueTTL_5000_THEN_QueueIsDeleted_WHEN_5000msAfterConnectionClosed()
        {
            using (var testScope = new QeueuNameTestScope())
            {
                var activator = Using(new BuiltinHandlerActivator());

                var configurer = Configure.With(activator)
                                 .Transport(t =>
                {
                    t.UseRabbitMq(RabbitMqTransportFactory.ConnectionString, testScope.QeueuName)
                    .InputQueueOptions(o => o.SetQueueTTL(100))
                    .AddClientProperties(new Dictionary <string, string> {
                        { "description", "CreateQueue_With_AutoDelete test in RabbitMqCreateQueueTest.cs" }
                    });
                });

                using (var bus = configurer.Start())
                {
                    Assert.IsTrue(bus.Advanced.Workers.Count > 0);
                }

                Thread.Sleep(5000);
                Assert.IsFalse(RabbitMqTransportFactory.QueueExists(testScope.QeueuName));
            }
        }
Esempio n. 3
0
        public async Task AutomaticallyCreatesDestinationQueue()
        {
            var queueName = TestConfig.GetName("does_not_exist_yet");

            RabbitMqTransportFactory.DeleteQueue(queueName);

            Thread.Sleep(1000);

            // first we send a message to a queue that does not exist at this time
            Console.WriteLine($"Sending 'hej med dig min ven!' message to '{queueName}'");
            await _bus.Advanced.Routing.Send(queueName, "hej med dig min ven!");

            Thread.Sleep(1000);

            // then we start a server listening on the queue
            var gotTheMessage = new ManualResetEvent(false);

            StartServer(queueName).Handle <string>(async str =>
            {
                gotTheMessage.Set();
            });

            Console.WriteLine("Waiting for message to arrive");
            gotTheMessage.WaitOrDie(TimeSpan.FromSeconds(5));
            Console.WriteLine("Got it :)");
        }
Esempio n. 4
0
        public void ThrowExceptionWhenQueueDoesNotExist()
        {
            var queueName = TestConfig.GetName("non-existing-queue");

            RabbitMqTransportFactory.DeleteQueue(queueName);

            Assert.ThrowsAsync <RebusApplicationException>(() => _bus.Advanced.Routing.Send(queueName, "hej"));
        }
Esempio n. 5
0
        protected override void SetUp()
        {
            RabbitMqTransportFactory.DeleteQueue(_publisherQueueName);
            RabbitMqTransportFactory.DeleteQueue(_subscriber1QueueName);
            RabbitMqTransportFactory.DeleteQueue(_subscriber2QueueName);

            _publisher = GetBus(_publisherQueueName);
        }
Esempio n. 6
0
        public void Dispose()
        {
            try
            {
                RabbitMqTransportFactory.DeleteQueue(_queueName);

                Console.WriteLine($"Queue '{_queueName}' deleted");
            }
            catch { }
        }
        protected override void SetUp()
        {
            RabbitMqTransportFactory.DeleteQueue(_inputQueueName);

            _activator = Using(new BuiltinHandlerActivator());

            Configure.With(_activator)
            .Logging(l => l.Console(LogLevel.Warn))
            .Transport(t => t.UseRabbitMq(ConnectionString, _inputQueueName))
            .Serialization(s => s.Decorate(c => new Utf8Fallback(c.Get <ISerializer>())))
            .Start();
        }
Esempio n. 8
0
        protected override void SetUp()
        {
            var queueName = TestConfig.QueueName("expressperf");

            RabbitMqTransportFactory.DeleteQueue(queueName);

            _activator = Using(new BuiltinHandlerActivator());

            _bus = Configure.With(_activator)
                   .Logging(l => l.ColoredConsole(LogLevel.Info))
                   .Transport(t => t.UseRabbitMq(RabbitMqTransportFactory.ConnectionString, queueName))
                   .Options(o => o.SetMaxParallelism(100))
                   .Start();
        }
        public async Task ReceiveOnSubscribe_WHEN_SubscriberQueueDeleted_THEN_ItThrowsException()
        {
            const string message = "Test-Message-123";

            using (var receivedEvent = new ManualResetEvent(false))
            {
                using (var publisher = StartBus(_publisherQueueName))
                {
                    async Task HandlerMethod(string data)
                    {
                        if (string.Equals(data, message))
                        {
                            receivedEvent.Set();
                        }
                    }

                    using (var subscriber = StartBus(_subscriberQueueName, HandlerMethod, false, false))
                    {
                        // create the input queue
                        RabbitMqTransportFactory.CreateQueue(_subscriberQueueName);

                        await subscriber.Subscribe <string>();

                        // remove the input queue
                        RabbitMqTransportFactory.DeleteQueue(_subscriberQueueName);

                        // wait a short while
                        await Task.Delay(5000);

                        // check that published message is received without problems
                        await publisher.Publish(message);

                        var result = receivedEvent.WaitOne(TimeSpan.FromSeconds(2));
                        Assert.IsFalse(result);
                    }
                }
            }
        }
Esempio n. 10
0
        public async Task CanUseCustomExchangeName()
        {
            const string connectionString = RabbitMqTransportFactory.ConnectionString;

            const string customDirectExchangeName = "Dingo";
            const string customTopicExchangeName  = "Topico";

            RabbitMqTransportFactory.DeleteExchange(RabbitMqOptionsBuilder.DefaultDirectExchangeName);
            RabbitMqTransportFactory.DeleteExchange(RabbitMqOptionsBuilder.DefaultTopicExchangeName);
            RabbitMqTransportFactory.DeleteExchange(customDirectExchangeName);
            RabbitMqTransportFactory.DeleteExchange(customTopicExchangeName);

            using (var activator = new BuiltinHandlerActivator())
            {
                var gotString = new ManualResetEvent(false);
                activator.Handle <string>(async str => gotString.Set());

                Configure.With(activator)
                .Transport(t =>
                {
                    var queueName = TestConfig.GetName("custom-exchange");

                    t.UseRabbitMq(connectionString, queueName)
                    .ExchangeNames(directExchangeName: customDirectExchangeName, topicExchangeName: customTopicExchangeName);
                })
                .Start();

                await activator.Bus.SendLocal("hej");

                gotString.WaitOrDie(TimeSpan.FromSeconds(3));
            }

            Assert.That(RabbitMqTransportFactory.ExchangeExists(RabbitMqOptionsBuilder.DefaultDirectExchangeName), Is.False);
            Assert.That(RabbitMqTransportFactory.ExchangeExists(RabbitMqOptionsBuilder.DefaultTopicExchangeName), Is.False);
            Assert.That(RabbitMqTransportFactory.ExchangeExists(customDirectExchangeName), Is.True);
            Assert.That(RabbitMqTransportFactory.ExchangeExists(customTopicExchangeName), Is.True);
        }
Esempio n. 11
0
 protected override void SetUp()
 {
     RabbitMqTransportFactory.DeleteQueue(_priorityQueueName);
 }
 protected override void TearDown()
 {
     base.TearDown();
     RabbitMqTransportFactory.DeleteQueue(_publisherQueueName);
     RabbitMqTransportFactory.DeleteQueue(_subscriberQueueName);
 }
 protected override void SetUp()
 {
     RabbitMqTransportFactory.DeleteQueue(_testQueue1);
 }
Esempio n. 14
0
 public void Dispose()
 {
     RabbitMqTransportFactory.DeleteQueue(QeueuName);
 }
Esempio n. 15
0
 protected override void SetUp()
 {
     RabbitMqTransportFactory.DeleteQueue(_noneExistingQueueName);
     RabbitMqTransportFactory.DeleteQueue(_mandatoryQueue);
 }