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<object>())).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); } }
protected void TestOutboxSending(string workQueueUriFormat, string errorQueueUriFormat, bool isTransactional) { const int count = 100; const int threadCount = 3; var padlock = new object(); var configuration = GetConfiguration(workQueueUriFormat, errorQueueUriFormat, threadCount, isTransactional); var messageRouteProvider = new Mock<IMessageRouteProvider>(); var receiverWorkQueueUri = string.Format(workQueueUriFormat, "test-receiver-work"); messageRouteProvider.Setup(m => m.GetRouteUris(It.IsAny<string>())).Returns(new[] {receiverWorkQueueUri}); configuration.MessageRouteProvider = messageRouteProvider.Object; Console.WriteLine("Sending {0} messages.", count); using (var bus = new ServiceBus(configuration)) { for (var i = 0; i < count; i++) { bus.Send(new SimpleCommand()); } var idleThreads = new List<int>(); bus.Events.ThreadWaiting += (sender, args) => { if (!args.PipelineType.FullName.Equals(typeof (OutboxPipeline).FullName)) { return; } lock (padlock) { if (idleThreads.Contains(Thread.CurrentThread.ManagedThreadId)) { return; } idleThreads.Add(Thread.CurrentThread.ManagedThreadId); } }; bus.Start(); while (idleThreads.Count < threadCount) { Thread.Sleep(25); } } using (var queueManager = QueueManager.Default()) { var receiverWorkQueue = queueManager.GetQueue(receiverWorkQueueUri); for (var i = 0; i < count; i++) { var receivedMessage = receiverWorkQueue.GetMessage(); Assert.IsNotNull(receivedMessage); receiverWorkQueue.Acknowledge(receivedMessage.AcknowledgementToken); } receiverWorkQueue.AttemptDrop(); var outboxWorkQueue = queueManager.GetQueue(string.Format(workQueueUriFormat, "test-outbox-work")); Assert.IsTrue(outboxWorkQueue.IsEmpty()); outboxWorkQueue.AttemptDrop(); queueManager.GetQueue(string.Format(errorQueueUriFormat, "test-error")).AttemptDrop(); } }
protected void TestInboxDeferred(string queueUriFormat) { var configuration = GetConfiguration(queueUriFormat, 1, false); var module = new InboxDeferredModule(); configuration.Modules.Add(module); Guid messageId; var messageType = typeof (ReceivePipelineCommand).FullName; using (var bus = new ServiceBus(configuration)) { bus.Start(); var transportMessage = bus.Send(new ReceivePipelineCommand(), c => c.Defer(DateTime.Now.AddMilliseconds(500)) .WithRecipient(configuration.Inbox.WorkQueue)); var timeout = DateTime.Now.AddMilliseconds(1000); Assert.IsNotNull(transportMessage); messageId = transportMessage.MessageId; while (module.TransportMessage == null && DateTime.Now < timeout) { Thread.Sleep(5); } } Assert.IsNotNull(module.TransportMessage); Assert.True(messageId.Equals(module.TransportMessage.MessageId)); Assert.True(messageType.Equals(module.TransportMessage.MessageType, StringComparison.OrdinalIgnoreCase)); }
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 mockMessageRouteProvider = Mock<IMessageRouteProvider>(); mockMessageRouteProvider.Stub(mock => mock.GetRouteUris(Arg<object>.Is.Anything)).Return(new List<string> { configuration.Inbox.WorkQueue.Uri.ToString() }); configuration.MessageRouteProvider = mockMessageRouteProvider; using (var bus = new ServiceBus(configuration)) { bus.Configuration.Modules.Add(new MockModule(this)); bus.Start(); bus.Send(command); var waitTill = DateTime.Now.AddMilliseconds(15000); while (DateTime.Now < waitTill && TransportMessage == null) { Thread.Sleep(50); } Assert.IsNotNull(TransportMessage); Assert.AreEqual(command.Name, ((SimpleCommand)bus.Configuration.Serializer.Deserialize(typeof(SimpleCommand), new MemoryStream(TransportMessage.Message))).Name); } }