Skip to content

Commit

Permalink
Merge pull request #49 from davecluderay/master
Browse files Browse the repository at this point in the history
#46 Handle scenarios where correlation ID is present but null
  • Loading branch information
SzymonPobiega authored May 24, 2022
2 parents 05f52fd + f97bc00 commit 1c15070
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/NServiceBus.Router/Pipeline/Forwarding/ReplyTraceRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected void AddTraceHeadersForRoutingBackReply(BaseForwardRuleContext context
newCorrelationId = newCorrelationId.AppendTLV("reply-to", replyToHeader);
}

if (context.ForwardedHeaders.TryGetValue(Headers.CorrelationId, out var correlationId))
if (context.ForwardedHeaders.TryGetValue(Headers.CorrelationId, out var correlationId) && correlationId != null)
{
newCorrelationId = newCorrelationId.AppendTLV("id", correlationId);
}
Expand All @@ -92,7 +92,7 @@ protected void AddTraceHeadersForRoutingBackReply(BaseForwardRuleContext context
/// </summary>
static void UnwrapCorrelationIdAndSetTraceHeader(BaseForwardRuleContext context)
{
if (context.ForwardedHeaders.TryGetValue(Headers.CorrelationId, out var correlationId))
if (context.ForwardedHeaders.TryGetValue(Headers.CorrelationId, out var correlationId) && correlationId != null)
{
while (true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ static string InterfaceForReply(ReplyPreroutingContext context)
string destinationIface = null;

if (!context.Headers.TryGetValue(RouterHeaders.ReplyToTrace, out var replyToTrace)
&& !context.Headers.TryGetValue(Headers.CorrelationId, out replyToTrace))
&& (!context.Headers.TryGetValue(Headers.CorrelationId, out replyToTrace) || replyToTrace is null))
{
throw new UnforwardableMessageException($"The reply has to contain either '{Headers.CorrelationId}' header set by the sending endpoint or '{RouterHeaders.ReplyToTrace}' set by the replying endpoint in order to be routed.");
}

try
{
replyToTrace.DecodeTLV((t, v) =>
Expand Down
5 changes: 5 additions & 0 deletions src/NServiceBus.Router/TypeLengthValueDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public static string AppendTLV(this string existingTLV, string type, string valu

public static bool TryDecodeTLV(this string tlvString, Action<string, string> valueCallback)
{
if (tlvString is null)
{
return false;
}

var remaining = tlvString;
while (true)
{
Expand Down

0 comments on commit 1c15070

Please sign in to comment.