예제 #1
0
        public async Task ItWorks()
        {
            const int numberOfRetries = 5;

            InitializeBus(numberOfRetries);

            var attemptedDeliveries = 0;

            _handlerActivator.Handle<string>(async _ =>
            {
                Interlocked.Increment(ref attemptedDeliveries);
                throw new ApplicationException("omgwtf!");
            });

            await _bus.Send("hej");

            using (var errorQueue = new MsmqTransport(ErrorQueueName, new ConsoleLoggerFactory(true)))
            {
                var failedMessage = await errorQueue.AwaitReceive();

                Assert.That(attemptedDeliveries, Is.EqualTo(numberOfRetries));
                Assert.That(failedMessage.Headers.GetValue(Headers.ErrorDetails), Contains.Substring("5 unhandled exceptions"));
                Assert.That(failedMessage.Headers.GetValue(Headers.SourceQueue), Is.EqualTo(InputQueueName));
            }
        }
        protected override void SetUp()
        {
            _transport = new MsmqTransport(_queueName, new ConsoleLoggerFactory(true));
            _transport.CreateQueue(_queueName);

            Using(_transport);

            Console.WriteLine(_queueName);
        }
예제 #3
0
파일: Program.cs 프로젝트: netojoaop/Rebus
        protected override void DoRun()
        {
            using (var transport = new MsmqTransport(InputQueue))
            {
                var returnToSourceQueue = new ReturnToSourceQueue(transport)
                {
                    InputQueue = InputQueue,
                    DefaultOutputQueue = DefaultOutputQueue
                };

                returnToSourceQueue.Run();
            }
        }
        /// <summary>
        /// Configures Rebus to use MSMQ to transport messages, receiving messages from the specified <paramref name="inputQueueName"/>
        /// </summary>
        public static MsmqTransportConfigurationBuilder UseMsmq(this StandardConfigurer<ITransport> configurer, string inputQueueName)
        {
            var builder = new MsmqTransportConfigurationBuilder();

            configurer.Register(c =>
            {
                var rebusLoggerFactory = c.Get<IRebusLoggerFactory>();
                var transport = new MsmqTransport(inputQueueName, rebusLoggerFactory);
                builder.Configure(transport);
                return transport;
            });

            return builder;
        }
        /// <summary>
        /// Configures Rebus to use MSMQ to transport messages, receiving messages from the specified <paramref name="inputQueueName"/>
        /// </summary>
        public static MsmqTransportConfigurationBuilder UseMsmq(this StandardConfigurer <ITransport> configurer, string inputQueueName)
        {
            var builder = new MsmqTransportConfigurationBuilder();

            configurer.Register(c =>
            {
                var rebusLoggerFactory = c.Get <IRebusLoggerFactory>();
                var transport          = new MsmqTransport(inputQueueName, rebusLoggerFactory);
                builder.Configure(transport);
                return(transport);
            });

            return(builder);
        }
        /// <summary>
        /// Configures Rebus to use MSMQ to transport messages as a one-way client (i.e. will not be able to receive any messages)
        /// </summary>
        public static MsmqTransportConfigurationBuilder UseMsmqAsOneWayClient(this StandardConfigurer<ITransport> configurer)
        {
            var builder = new MsmqTransportConfigurationBuilder();

            configurer.Register(c =>
            {
                var rebusLoggerFactory = c.Get<IRebusLoggerFactory>();
                var transport = new MsmqTransport(null, rebusLoggerFactory);
                builder.Configure(transport);
                return transport;
            });

            OneWayClientBackdoor.ConfigureOneWayClient(configurer);

            return builder;
        }
        /// <summary>
        /// Configures Rebus to use MSMQ to transport messages as a one-way client (i.e. will not be able to receive any messages)
        /// </summary>
        public static MsmqTransportConfigurationBuilder UseMsmqAsOneWayClient(this StandardConfigurer <ITransport> configurer)
        {
            var builder = new MsmqTransportConfigurationBuilder();

            configurer.Register(c =>
            {
                var rebusLoggerFactory = c.Get <IRebusLoggerFactory>();
                var transport          = new MsmqTransport(null, rebusLoggerFactory);
                builder.Configure(transport);
                return(transport);
            });

            OneWayClientBackdoor.ConfigureOneWayClient(configurer);

            return(builder);
        }
예제 #8
0
        public ITransport Create(string inputQueueAddress)
        {
            var transport = new MsmqTransport(inputQueueAddress, new ConsoleLoggerFactory(true));

            _disposables.Add(transport);

            if (inputQueueAddress != null)
            {
                transport.PurgeInputQueue();
            }

            transport.Initialize();

            if (inputQueueAddress != null)
            {
                _queuesToDelete.Add(inputQueueAddress);
            }

            return transport;
        }
예제 #9
0
        public async Task CanConfigureNumberOfRetries(int numberOfRetries)
        {
            InitializeBus(numberOfRetries);

            var attemptedDeliveries = 0;

            _handlerActivator.Handle<string>(async _ =>
            {
                Interlocked.Increment(ref attemptedDeliveries);
                throw new ApplicationException("omgwtf!");
            });

            await _bus.Send("hej");

            using (var errorQueue = new MsmqTransport(ErrorQueueName, new ConsoleLoggerFactory(true)))
            {
                var expectedNumberOfAttemptedDeliveries = numberOfRetries;

                await errorQueue.AwaitReceive(2 + numberOfRetries / 10.0);

                Assert.That(attemptedDeliveries, Is.EqualTo(expectedNumberOfAttemptedDeliveries));
            }
        }
예제 #10
0
        static List<int> SendMessages(int messageCount)
        {
            var transport = new MsmqTransport(QueueName);

            MsmqUtil.EnsureQueueExists(MsmqUtil.GetPath(QueueName));

            var sendIds = new List<int>();

            Enumerable.Range(0, messageCount)
                .Select(id => new SomeMessage { Id = id })
                .ToList()
                .ForEach(msg =>
                {
                    using (var context = new DefaultTransactionContext())
                    {
                        transport.Send(QueueName, TransportMessageHelpers.FromString(JsonConvert.SerializeObject(msg)),
                            context).Wait();

                        context.Complete().Wait();

                        sendIds.Add(msg.Id);
                    }
                });

            return sendIds;
        }
 internal void Configure(MsmqTransport transport)
 {
     _onCreatedCallbacks.ForEach(transport.AddQueueCallback);
 }
 internal void Configure(MsmqTransport transport)
 {
     _onCreatedCallbacks.ForEach(transport.AddQueueCallback);
 }