Exemple #1
0
        public void Should_be_able_to_send_a_message_to_a_routed_queue()
        {
            var command = new SimpleCommand
                                            {
                                                Name = Guid.NewGuid().ToString()
                                            };

            var configuration = CreateMemoryConfiguration();

            var module = new ServiceBusRoutingModule();

            configuration.Modules.Add(module);

            var mockMessageRouteProvider = new Mock<IMessageRouteProvider>();

            mockMessageRouteProvider.Setup(mock => mock.GetRouteUris(It.IsAny<string>())).Returns(new List<string>
            {
              configuration.Inbox.WorkQueue.Uri.ToString()
            });

            configuration.MessageRouteProvider = mockMessageRouteProvider.Object;

            using (var bus = new ServiceBus(configuration))
            {
                bus.Start();

                bus.Send(command);

                var timeout = DateTime.Now.AddMilliseconds(5000);

                while (DateTime.Now < timeout && module.SimpleCommand == null)
                {
                    Thread.Sleep(50);
                }

                Assert.IsNotNull(module.SimpleCommand);
                Assert.AreEqual(command.Name, module.SimpleCommand.Name);
            }
        }
Exemple #2
0
        private void EnqueueDeferredMessage(IServiceBus bus, DateTime ignoreTillDate)
        {
            var command = new SimpleCommand
                {
                    Name = Guid.NewGuid().ToString()
                };

            var message = bus.CreateTransportMessage(command, c => c.Defer(ignoreTillDate)
                         .WithRecipient(bus.Configuration.Inbox.WorkQueue));

            bus.Configuration.Inbox.WorkQueue.Enqueue(message.MessageId, bus.Configuration.Serializer.Serialize(message));

            _log.Information(string.Format("[message enqueued] : name = '{0}' / deferred till date = '{1}'", command.Name, message.IgnoreTillDate));
        }