Particular / NServiceBus.MessagingBridge

Other
4 stars 1 forks source link

Msmq remote addresses can't be configured #505

Closed andreasohlund closed 1 week ago

andreasohlund commented 2 weeks ago

Configuring a custom queue address with a specific server name specified, eg. endpoint@servername, to enable the bridge to forward messages to remote MSMQ servers causes an exception

Bugreport: https://discuss.particular.net/t/issue-configuring-nservicebus-messagingbridge-to-use-msmq-on-a-different-host-machine/

Symptoms

Message shovel operations fail:

Message shovel operation failed and will be retried - System.Exception: Failed to shovel message for endpoint AddressWithMachinename.ReceivingEndpoint with id d8a4bfe8-a5a7-44f9-9de5-b375a6993873 from DefaultTestingTransport to testablemsmq
    ---> System.ArgumentException: Address contains multiple @ characters.

Workaround

As a workaround reflection can be used to create affected BridgeEndpoints.

public static BridgeEndpoint Create(string endpointAddress)
{
    var addressParts = endpointAddress.Split('@');
    if (addressParts.Length > 1)
    {
        var endpoint = new BridgeEndpoint(addressParts[0]);
        var fieldInfo = typeof(BridgeEndpoint).GetField("<QueueAddress>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance);
        var queueAddress = new QueueAddress(addressParts[0], properties: new Dictionary<string, string> { { "machine", addressParts[1] } });
        fieldInfo!.SetValue(endpoint, queueAddress);
        return endpoint;
    }

    return new BridgeEndpoint(addressParts[0]);
}

See https://discuss.particular.net/t/issue-configuring-nservicebus-messagingbridge-to-use-msmq-on-a-different-host-machine/4069/6 for more details.

andreasohlund commented 2 weeks ago

@abparticular @jpalac FYI this reproduces the issue but I'm starting to realize that this highlights a bigger issue with how the bridge does addressing. I have some ideas that we can discuss once you are back

udidahan commented 1 week ago

Was some follow-through taken for this part @andreasohlund ?

I'm starting to realize that this highlights a bigger issue with how the bridge does addressing. I have some ideas that we can discuss once you are back

andreasohlund commented 1 week ago

@udidahan After some discussions with the people involved this turned out to be a red herring, the fix in this PR is all that is needed.