Skip to content

Commit

Permalink
- improved error handling in queue manager
Browse files Browse the repository at this point in the history
  • Loading branch information
eben-roux committed Jul 23, 2015
1 parent 28f573a commit 215ae20
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 13 deletions.
7 changes: 6 additions & 1 deletion Shuttle.ESB.Core.Tests/NullQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
27 changes: 27 additions & 0 deletions Shuttle.ESB.Core.Tests/NullQueueFactory.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
5 changes: 1 addition & 4 deletions Shuttle.ESB.Core.Tests/Shuttle.ESB.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyMessageRouteSpecificationTest.cs" />
Expand All @@ -61,6 +57,7 @@
<Compile Include="Messages\OtherNamespaceCommand.cs" />
<Compile Include="Messages\SimpleEvent.cs" />
<Compile Include="NullQueue.cs" />
<Compile Include="NullQueueFactory.cs" />
<Compile Include="Pipeline\MockAuthenticateObserver.cs" />
<Compile Include="Pipeline\MockPipelineEvent1.cs" />
<Compile Include="Pipeline\PipelineTest.cs" />
Expand Down
8 changes: 4 additions & 4 deletions Shuttle.ESB.Core.Tests/TransportMessageConfiguratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
18 changes: 18 additions & 0 deletions Shuttle.ESB.Core/ESBResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Shuttle.ESB.Core/ESBResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,12 @@
<value>Could not get type: {0}</value>
<comment>{0} = type descriptor that cannot be found</comment>
</data>
<data name="FindQueueException" xml:space="preserve">
<value>An exception occurred trying to find a queue. Candidate queue type = '{0}'. Candidate uri = '{1}'. Comparison uri = '{2}'. All exception messages = '{3}'.</value>
<comment>{0} = candidate queue type, {1} = candidate uri, {2} = comparison uri, {3} = all exception messages</comment>
</data>
<data name="QueueFactoryCreatedNullQueue" xml:space="preserve">
<value>Queue factory with type '{0}' create returned (null) for uri '{1}'.</value>
<comment>{0} = the queue factory type name, {1} = the uri that the factory was requested to create the queue for</comment>
</data>
</root>
40 changes: 36 additions & 4 deletions Shuttle.ESB.Core/Queues/QueueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit 215ae20

Please sign in to comment.