diff --git a/Shuttle.ESB.Core.Tests/NullQueue.cs b/Shuttle.ESB.Core.Tests/NullQueue.cs index e561b43e..7e148e47 100644 --- a/Shuttle.ESB.Core.Tests/NullQueue.cs +++ b/Shuttle.ESB.Core.Tests/NullQueue.cs @@ -6,8 +6,13 @@ namespace Shuttle.ESB.Core.Tests public class NullQueue : IQueue { public NullQueue(string uri) + : this(new Uri(uri)) { - Uri = new Uri(uri); + } + + public NullQueue(Uri uri) + { + Uri = uri; } public Uri Uri { get; private set; } diff --git a/Shuttle.ESB.Core.Tests/NullQueueFactory.cs b/Shuttle.ESB.Core.Tests/NullQueueFactory.cs new file mode 100644 index 00000000..2ba44b94 --- /dev/null +++ b/Shuttle.ESB.Core.Tests/NullQueueFactory.cs @@ -0,0 +1,27 @@ +using System; +using NUnit.Framework; + +namespace Shuttle.ESB.Core.Tests +{ + public class NullQueueFactory : IQueueFactory + { + public NullQueueFactory() + { + Scheme = "null-queue"; + } + + public string Scheme { get; private set; } + + public IQueue Create(Uri uri) + { + Guard.ArgumentNotNull(uri, "uri"); + + return new NullQueue(uri); + } + + public bool CanCreate(Uri uri) + { + return uri.Scheme.Equals(Scheme, StringComparison.InvariantCultureIgnoreCase); + } + } +} \ No newline at end of file diff --git a/Shuttle.ESB.Core.Tests/Shuttle.ESB.Core.Tests.csproj b/Shuttle.ESB.Core.Tests/Shuttle.ESB.Core.Tests.csproj index 8bf957ad..da9b1599 100644 --- a/Shuttle.ESB.Core.Tests/Shuttle.ESB.Core.Tests.csproj +++ b/Shuttle.ESB.Core.Tests/Shuttle.ESB.Core.Tests.csproj @@ -47,10 +47,6 @@ - - - - @@ -61,6 +57,7 @@ + diff --git a/Shuttle.ESB.Core.Tests/TransportMessageConfiguratorTest.cs b/Shuttle.ESB.Core.Tests/TransportMessageConfiguratorTest.cs index db7b24b8..bdc60d40 100644 --- a/Shuttle.ESB.Core.Tests/TransportMessageConfiguratorTest.cs +++ b/Shuttle.ESB.Core.Tests/TransportMessageConfiguratorTest.cs @@ -13,15 +13,15 @@ public void Should_be_able_to_set_sender() { Inbox = new InboxQueueConfiguration { - WorkQueue = new NullQueue("nq://./work-queue") + WorkQueue = new NullQueue("null-queue://./work-queue") } }; - Assert.AreEqual("nq://./work-queue", configurator.TransportMessage(configuration).SenderInboxWorkQueueUri); + Assert.AreEqual("null-queue://./work-queue", configurator.TransportMessage(configuration).SenderInboxWorkQueueUri); - configurator.WithSender("nq://./another-queue"); + configurator.WithSender("null-queue://./another-queue"); - Assert.AreEqual("nq://./another-queue", configurator.TransportMessage(configuration).SenderInboxWorkQueueUri); + Assert.AreEqual("null-queue://./another-queue", configurator.TransportMessage(configuration).SenderInboxWorkQueueUri); } } } \ No newline at end of file diff --git a/Shuttle.ESB.Core/ESBResources.Designer.cs b/Shuttle.ESB.Core/ESBResources.Designer.cs index bd210b69..5b01cabb 100644 --- a/Shuttle.ESB.Core/ESBResources.Designer.cs +++ b/Shuttle.ESB.Core/ESBResources.Designer.cs @@ -150,6 +150,15 @@ public static string FatalIdempotenceServiceException { } } + /// + /// Looks up a localized string similar to An exception occurred trying to find a queue. Candidate queue type = '{0}'. Candidate uri = '{1}'. Comparison uri = '{2}'. All exception messages = '{3}'.. + /// + public static string FindQueueException { + get { + return ResourceManager.GetString("FindQueueException", resourceCulture); + } + } + /// /// Looks up a localized string similar to dd MMM yyyy HH:mm:ss. /// @@ -366,6 +375,15 @@ public static string PublishWithoutSubscriptionManagerException { } } + /// + /// Looks up a localized string similar to Queue factory with type '{0}' create returned (null) for uri '{1}'.. + /// + public static string QueueFactoryCreatedNullQueue { + get { + return ResourceManager.GetString("QueueFactoryCreatedNullQueue", resourceCulture); + } + } + /// /// Looks up a localized string similar to Queue factory could not be instantiated: {0}. /// diff --git a/Shuttle.ESB.Core/ESBResources.resx b/Shuttle.ESB.Core/ESBResources.resx index ce3e09f5..34335d38 100644 --- a/Shuttle.ESB.Core/ESBResources.resx +++ b/Shuttle.ESB.Core/ESBResources.resx @@ -432,4 +432,12 @@ Could not get type: {0} {0} = type descriptor that cannot be found + + An exception occurred trying to find a queue. Candidate queue type = '{0}'. Candidate uri = '{1}'. Comparison uri = '{2}'. All exception messages = '{3}'. + {0} = candidate queue type, {1} = candidate uri, {2} = comparison uri, {3} = all exception messages + + + Queue factory with type '{0}' create returned (null) for uri '{1}'. + {0} = the queue factory type name, {1} = the uri that the factory was requested to create the queue for + \ No newline at end of file diff --git a/Shuttle.ESB.Core/Queues/QueueManager.cs b/Shuttle.ESB.Core/Queues/QueueManager.cs index 21e228d4..09e786f4 100644 --- a/Shuttle.ESB.Core/Queues/QueueManager.cs +++ b/Shuttle.ESB.Core/Queues/QueueManager.cs @@ -113,6 +113,8 @@ public IQueueFactory GetQueueFactory(Uri uri) public IQueue GetQueue(string uri) { + Guard.AgainstNullOrEmptyString(uri, "uri"); + var queue = _queues.Find( candidate => Find(candidate, uri)); @@ -149,11 +151,11 @@ public IQueue GetQueue(string uri) throw new KeyNotFoundException(string.Format(ESBResources.UriNameNotFoundException, UriResolver.GetType().FullName, uri)); } - queue = new ResolvedQueue(GetQueueFactory(resolvedQueueUri).Create(resolvedQueueUri), queueUri); + queue = new ResolvedQueue(CreateQueue(GetQueueFactory(resolvedQueueUri), resolvedQueueUri), queueUri); } else { - queue = GetQueueFactory(queueUri).Create(queueUri); + queue = CreateQueue(GetQueueFactory(queueUri), queueUri); } _queues.Add(queue); @@ -162,9 +164,39 @@ public IQueue GetQueue(string uri) } } - private static bool Find(IQueue candidate, string uri) + private IQueue CreateQueue(IQueueFactory queueFactory, Uri queueUri) + { + var result = queueFactory.Create(queueUri); + + Guard.AgainstNull(result, string.Format(ESBResources.QueueFactoryCreatedNullQueue, queueFactory.GetType().FullName, queueUri.ToString())); + + return result; + } + + + private bool Find(IQueue candidate, string uri) { - return candidate.Uri.ToString().Equals(uri, StringComparison.InvariantCultureIgnoreCase); + try + { + return candidate.Uri.ToString().Equals(uri, StringComparison.InvariantCultureIgnoreCase); + } + catch (Exception ex) + { + var candidateTypeName = "(candidate is null)"; + var candidateUri= "(candidate is null)"; + + if (candidate != null) + { + candidateTypeName = candidate.GetType().FullName; + candidateUri = candidate.Uri != null + ? candidate.Uri.ToString() + : "(candidate.Uri is null)"; + } + + _log.Error(string.Format(ESBResources.FindQueueException, candidateTypeName, candidateUri, uri ?? "(comparison uri is null)", ex.AllMessages())); + + return false; + } } public IQueue CreateQueue(string uri)