Particular / NServiceBus.MessagingBridge

Other
4 stars 1 forks source link

Translation lookup is case sensitive and leads to error when configured lower respectively upper case #175

Closed FabianTrottmann closed 1 year ago

FabianTrottmann commented 1 year ago

The translation of a source address to target address within the bridge by using NServiceBus.ReplyTo as a key fails, if e.g hostname in the ReplyTo header field is upper case whereas the BridgeEndpoint has been configured with lowercase hostname letters.

I get the following exception:

MESSAGE: Message shovel operation failed, message will be moved to error@HostErrorQueue
  System.Exception: Failed to shovel message for endpoint endpoint1 with id 9e2d8d2d-0a41-430c-8441-1eae8795e91a\1009387202 
  from msmq to azureservicebus ---> System.Exception: No target address mapping could be found for source address: 
  endpoint2@HOST-VM1

My Bridge Endpoint Mapping (host-vm1 is lowercase):

var endpoint2 = new BridgeEndpoint("endpoint2", "host-vm1");

Case-sensitive lookup in NServiceBus.Transport.Bridge:

public string TranslateToTargetAddress(string sourceAddress)
{
    if (targetEndpointAddressMappings.TryGetValue(sourceAddress, out var targetAddress))
    {
        return targetAddress;
    }
    throw new Exception($"No target address mapping could be found for source address: {sourceAddress}");
}

Of course, there is a simple workaround as long as the behavior is consistent for all messages within the same endpoint. I simply configure the specific BridgeEndpoint according to the replyTo Address (upper or lower case of the hostname).

Oddly, some of our MSMQ endpoints send messages with lowercase hostname in ReplyToAdress and some others with uppercase (I don't know why). So we have a mix of lower and upper case BridgeEndpoint configurations.

Question: is it required to make the lookup case-sensitive, or could it be case-insensitive?

WilliamBZA commented 1 year ago

The bridge is transport agnostic, so needs to work with all supported transports. Unfortunately, this means working with the lowest common denominator. In this specific case, some transports are case sensitive (e.g. RabbitMQ) while others aren't.

So to answer your question: It is unfortunately required for the lookup to be case sensitive.

With that out of the way, we could look at adding a configuration option to be case insensitive. I'll add a feature request to the bridge so that we can look at getting something like that in.

kbaley commented 1 year ago

For now, I've added a note to our documentation to let people know that the lookup is case-sensitive. When this issue is addressed, we can remove the note:

image