Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

routing key bug fix and wild card support #95

Closed
wants to merge 4 commits into from

Conversation

Calidus
Copy link
Contributor

@Calidus Calidus commented Jun 17, 2020

#94

Replace RoutingKey with RoutingKeyName and RoutingKeyValue. If RoutingKeyValue is not null but RoutingKeyName is null, a invalid argument exception is thrown. This seems like the best option. The only other thing that I thought of was maybe using a tuple instead of two different properties.

#93

Added wildcard support for RoutingKeyValue by using a regex in ShouldDeliverMessage(). Added test methods for wildcard support.


[Subscribe]
/// <summary>
/// This Subscription should only get SampleEvents who messages end in a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is incomplete.

/// </summary>
/// <param name="sampleEvent"></param>
/// <returns></returns>
[Subscribe(routingKeyName: "Message", routingKeyValue: "*1")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not thinking of separating the name and value in the Subscribe attribute, but just splitting it in the ReferenceWrapper constructor. This way breaks backwards compatibility, which I would like to avoid. The only files that should need to change (besides tests and examples) is ReferenceWrapper.

protected ReferenceWrapper(string routingKey = null)
/// <param name="routingKeyName">Optional Message property path used for routing</param>
/// <param name="routingKeyValue">Optional value to match with message payload content used for routing.</param>
protected ReferenceWrapper(string routingKeyName = null, string routingKeyValue = null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this to accept a single parameter 'routingKey'. Split on '=' and validate as it was doing before. Then assign RoutingKeyName and RoutingKeyValue instead of RoutingKey.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to go the regex route should we still have a RoutingKeyValue property that is a string or should we just create the regex in the constructor?

@@ -54,5 +54,246 @@ public void WhenDeterminingShouldDeliverMessageToActorWithUnmatchingPayload_Then
bool shouldDeliver = actorRef.ShouldDeliverMessage(messageWrapper);
Assert.IsFalse(shouldDeliver);
}
[TestMethod]
public void WhenDeterminingShouldDeliverMessageToActorWithUnmatchingPayload_ThenReturnsTrue()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test name should be "WhenDeterminingShouldDeliverMessageToActorWithMatchingPayload_ThenReturnsTrue".

@@ -54,5 +54,246 @@ public void WhenDeterminingShouldDeliverMessageToActorWithUnmatchingPayload_Then
bool shouldDeliver = actorRef.ShouldDeliverMessage(messageWrapper);
Assert.IsFalse(shouldDeliver);
}
[TestMethod]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space between the methods.

Assert.IsFalse(shouldDeliver);
}
[TestMethod]
public void WhenDeterminingShouldDeliverMessageToActorWithUnmatchingPayloadWithStartingWildCard__ThenReturnsTrue()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test name should be "WhenDeterminingShouldDeliverMessageToActorWithMatchingPayloadWithStartingWildCard__ThenReturnsTrue".

bool shouldDeliver = actorRef.ShouldDeliverMessage(messageWrapper);
Assert.IsFalse(shouldDeliver);
}
[TestMethod]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an empty line between methods.

Assert.IsFalse(shouldDeliver);
}
[TestMethod]
public void WhenDeterminingShouldDeliverMessageToActorWithUnmatchingPayloadWithEndingWildCard__ThenReturnsTrue()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test name should be "WhenDeterminingShouldDeliverMessageToActorWithMatchingPayloadWithEndingWildCard__ThenReturnsTrue".

Assert.IsFalse(shouldDeliver);
}
[TestMethod]
public void WhenDeterminingShouldDeliverMessageToActorWithUnmatchingPayloadWithMultipleWildCard__ThenReturnsTrue()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test name should be "WhenDeterminingShouldDeliverMessageToActorWithMatchingPayloadWithMultipleWildCard__ThenReturnsTrue".

string value = (string)token.SelectToken(RoutingKeyName);
if(value is null)
return false;
var regex = new Regex("^" + Regex.Escape(RoutingKeyValue).Replace(@"\*", ".*") + "$");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me think we might as well just go all the way and support any regex for the RoutingKey instead of inventing a custom and less flexible wildcard scheme.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is good idea but it would be a breaking change that would only show up while running which sounds dangerous.

Copy link
Contributor Author

@Calidus Calidus Jun 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on adding a new bool to the Subscribe Attribute, something like UseRegexForRouting.

if (UseRegexForRouting) {
// regex compare
} else {
// string.equals
}

This wouldn't prevent any breaking changes, if someone had used regex reserved characters in there RoutingKey.

@Calidus
Copy link
Contributor Author

Calidus commented Jun 18, 2020

Since most of changes requested are just undoing the changes that I made, it is easier or better if I make a new branch and a new PR?

@danadesrosiers
Copy link
Collaborator

Whatever is easiest for you. Either way works for me.

@Calidus
Copy link
Contributor Author

Calidus commented Jun 19, 2020

Closing this PR. I will submit a new one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants