public void YeahItDoes()
        {
            var deliveryAttempts = 0;

            adapter.Handle <string>(str =>
            {
                Interlocked.Increment(ref deliveryAttempts);
                throw new ApplicationException(RecognizableErrorMessage);
            });

            adapter.Bus.SendLocal("HELLO MY FRIEND!!!!!2222");

            var timeout = 5.Seconds();

            Assert.That(resetEvent.WaitOne(timeout), Is.True, "Did not receive PoisonMessage event within {0} timeout", timeout);
            Assert.That(deliveryAttempts, Is.EqualTo(5), "Expected 5 failed delivery attempts to have been made");

            // be sure that message has moved and everything
            Thread.Sleep(1.Seconds());

            using (var errorQueueClient = new AzureServiceBusMessageQueue(ConnectionString, ErrorQueueName))
            {
                var receivedTransportMessage = errorQueueClient.ReceiveMessage(new NoTransaction());

                Assert.That(receivedTransportMessage, Is.Not.Null);
            }
        }
Esempio n. 2
0
        protected override void DoSetUp()
        {
            SqlServerFixtureBase.DropTable(SagaIndex);
            SqlServerFixtureBase.DropTable(SagaTable);

            var busConnection = AzureServiceBusMessageQueueFactory.ConnectionString;
            var sqlConnection = SqlServerFixtureBase.ConnectionString;

            using (var azureQueue = new AzureServiceBusMessageQueue(busConnection, InputQueueName))
            {
                azureQueue.Purge();
            }

            allRepliesReceived = new ManualResetEvent(false);

            adapter = new BuiltinContainerAdapter();
            adapter.Register(() => new RequestHandler(adapter.Bus));

            sagaPersister = new SqlServerSagaPersister(sqlConnection, SagaIndex, SagaTable).EnsureTablesAreCreated();

            Configure.With(TrackDisposable(adapter))
            .Logging(l => l.ColoredConsole(minLevel: LogLevel.Warn))
            .Transport(t => t.UseAzureServiceBus(busConnection, InputQueueName, "error"))
            .Sagas(s => s.Use(sagaPersister))
            .CreateBus()
            .Start(3);
        }
Esempio n. 3
0
        protected override void DoSetUp()
        {
            events = new ConcurrentQueue <string>();
            builtinContainerAdapter = new BuiltinContainerAdapter();

            TrackDisposable(builtinContainerAdapter);

            using (var q = new AzureServiceBusMessageQueue(AzureServiceBusMessageQueueFactory.ConnectionString, QueueName))
            {
                q.Purge();
            }

            Configure.With(builtinContainerAdapter)
            .Logging(l => l.Console(minLevel: LogLevel.Info))
            .Transport(t => t.UseAzureServiceBus(AzureServiceBusMessageQueueFactory.ConnectionString, QueueName, "error"))
            .Events(e =>
            {
                e.MessageContextEstablished += (bus, context) =>
                {
                    WriteEvent("msg context established");

                    context.Disposed += () =>
                    {
                        WriteEvent("msg context disposed");
                    };
                };

                e.AddUnitOfWorkManager(new EventOutputtingUnitOfWorkManager(text => WriteEvent(text)));
            })
            .CreateBus().Start(1);
        }
        public void YeahItDoes()
        {
            var deliveryAttempts = 0;
            adapter.Handle<string>(str =>
                {
                    Interlocked.Increment(ref deliveryAttempts);
                    throw new ApplicationException(RecognizableErrorMessage);
                });

            adapter.Bus.SendLocal("HELLO MY FRIEND!!!!!2222");

            var timeout = 5.Seconds();
            Assert.That(resetEvent.WaitOne(timeout), Is.True, "Did not receive PoisonMessage event within {0} timeout", timeout);
            Assert.That(deliveryAttempts, Is.EqualTo(5), "Expected 5 failed delivery attempts to have been made");

            // be sure that message has moved and everything
            Thread.Sleep(1.Seconds());

            using (var errorQueueClient = new AzureServiceBusMessageQueue(ConnectionString, ErrorQueueName))
            {
                var receivedTransportMessage = errorQueueClient.ReceiveMessage(new NoTransaction());

                Assert.That(receivedTransportMessage, Is.Not.Null);
            }
        }
Esempio n. 5
0
        static List <ReceivedTransportMessage> GetAllTheMessages(AzureServiceBusMessageQueue azureServiceBusMessageQueue, ITransactionContext transactionContext)
        {
            var messages = new List <ReceivedTransportMessage>();
            ReceivedTransportMessage transportMessage;

            while ((transportMessage = azureServiceBusMessageQueue.ReceiveMessage(transactionContext)) != null)
            {
                messages.Add(transportMessage);
            }

            return(messages);
        }
        void InitializeBus(int numberOfRetries, BuiltinContainerAdapter adapter, ManualResetEvent poisonEventToSet)
        {
            RebusLoggerFactory.Current = new ConsoleLoggerFactory(false) { MinLevel = LogLevel.Warn };

            var connectionString = AzureServiceBusMessageQueueFactory.ConnectionString;

            using (var queue = new AzureServiceBusMessageQueue(connectionString, "test_input"))
            {
                queue.Purge();
            }

            Configure.With(adapter)
                .Transport(t => t.UseAzureServiceBus(connectionString, "test_input", "error"))
                .Behavior(b => b.SetMaxRetriesFor<FacilityException>(numberOfRetries))
                .Events(e => e.PoisonMessage += (bus, message, info) => poisonEventToSet.Set())
                .CreateBus()
                .Start(1);
        }
        void InitializeBus(int numberOfRetries, BuiltinContainerAdapter adapter, ManualResetEvent poisonEventToSet)
        {
            RebusLoggerFactory.Current = new ConsoleLoggerFactory(false)
            {
                MinLevel = LogLevel.Warn
            };

            var connectionString = AzureServiceBusMessageQueueFactory.ConnectionString;

            using (var queue = new AzureServiceBusMessageQueue(connectionString, "test_input"))
            {
                queue.Delete();
            }

            Configure.With(adapter)
            .Transport(t => t.UseAzureServiceBus(connectionString, "test_input", "error"))
            .Behavior(b => b.SetMaxRetriesFor <FacilityException>(numberOfRetries))
            .Events(e => e.PoisonMessage += (bus, message, info) => poisonEventToSet.Set())
            .CreateBus()
            .Start(1);
        }
        protected override void DoSetUp()
        {
            events = new ConcurrentQueue <string>();

            adapter = new BuiltinContainerAdapter();

            TrackDisposable(adapter);

            using (var queue = new AzureServiceBusMessageQueue(connectionString, QueueName))
            {
                queue.Delete();
            }

            AzureServiceBusMessageQueue.PeekLockDurationOnQueueInitialization = TimeSpan.FromMinutes(1);

            Configure.With(adapter)
            .Logging(l => l.Console(minLevel: LogLevel.Info))
            .Transport(t => t.UseAzureServiceBus(connectionString, QueueName, "error")
                       .AutomaticallyRenewPeekLockEvery(TimeSpan.FromMinutes(0.8)))
            .CreateBus()
            .Start();
        }
Esempio n. 9
0
        static void Run(Parameters parameters)
        {
            if (string.IsNullOrWhiteSpace(parameters.ErrorQueueName))
            {
                throw new NiceException("Please specify the name of an error queue");
            }

            using (var tx = new TransactionScope())
            {
                var transactionContext = new AmbientTransactionContext();

                if (!AzureServiceBusErrorQueueExists(parameters))
                {
                    throw new NiceException("The Azure Service Bus queue '{0}' does not exist!", parameters.ErrorQueueName);
                }

                var azureServiceBusMessageQueue = new AzureServiceBusMessageQueue(parameters.ConnectionString, parameters.ErrorQueueName);
                var allTheMessages = GetAllTheMessages(azureServiceBusMessageQueue, transactionContext);

                foreach (var message in allTheMessages)
                {
                    var transportMessageToSend = message.ToForwardableMessage();

                    try
                    {
                        if (!transportMessageToSend.Headers.ContainsKey(Headers.SourceQueue))
                        {
                            throw new NiceException(
                                      "Message {0} does not have a source queue header - it will be moved back to the input queue",
                                      message.Id);
                        }

                        var sourceQueue = (string)transportMessageToSend.Headers[Headers.SourceQueue];

                        if (parameters.AutoMoveAllMessages.GetValueOrDefault())
                        {
                            azureServiceBusMessageQueue.Send(sourceQueue, transportMessageToSend, transactionContext);

                            Print("Moved {0} to {1}", message.Id, sourceQueue);
                        }
                        else
                        {
                            var answer = PromptChar(new[] { 'y', 'n' }, "Would you like to move {0} to {1}? (y/n)",
                                                    message.Id, sourceQueue);

                            if (answer == 'y')
                            {
                                azureServiceBusMessageQueue.Send(sourceQueue, transportMessageToSend, transactionContext);

                                Print("Moved {0} to {1}", message.Id, sourceQueue);
                            }
                            else
                            {
                                azureServiceBusMessageQueue.Send(azureServiceBusMessageQueue.InputQueueAddress,
                                                                 transportMessageToSend,
                                                                 transactionContext);

                                Print("Moved {0} to {1}", message.Id, azureServiceBusMessageQueue.InputQueueAddress);
                            }
                        }
                    }
                    catch (NiceException e)
                    {
                        Print(e.Message);

                        azureServiceBusMessageQueue.Send(azureServiceBusMessageQueue.InputQueueAddress,
                                                         transportMessageToSend,
                                                         transactionContext);
                    }
                }

                if (parameters.DryRun.GetValueOrDefault())
                {
                    Print("Aborting queue transaction");
                    return;
                }

                if (!parameters.Interactive)
                {
                    tx.Complete();
                    return;
                }

                var commitAnswer = PromptChar(new[] { 'y', 'n' }, "Would you like to commit the queue transaction?");

                if (commitAnswer == 'y')
                {
                    Print("Committing queue transaction");

                    tx.Complete();
                    return;
                }

                Print("Queue transaction aborted");
            }
        }