Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved TCP support for MSMQ transport. Can now specify IP address f…

…or target queue and have responses returned to the IP address of the sender. This is important for remote clients connecting over a VPN whose machine name will not be possible to resolve in the domain.
  • Loading branch information...
commit b584490b1bd1c700ce44141e32510d82a052ae91 1 parent 19681e6
@udidahan udidahan authored
View
2  src/impl/unicast/queuing/NServiceBus.Unicast.Queuing.Msmq/MsmqMessageSender.cs
@@ -31,7 +31,7 @@ public void Send(TransportMessage message, string destination)
toSend.UseJournalQueue = UseJournalQueue;
if (!string.IsNullOrEmpty(message.ReturnAddress))
- toSend.ResponseQueue = new MessageQueue(MsmqUtilities.GetFullPath(message.ReturnAddress));
+ toSend.ResponseQueue = new MessageQueue(MsmqUtilities.GetReturnAddress(message.ReturnAddress, destination));
if (message.TimeToBeReceived < MessageQueue.InfiniteTimeout)
toSend.TimeToBeReceived = message.TimeToBeReceived;
View
BIN  src/impl/unicast/queuing/queuing.suo
Binary file not shown
View
51 src/utils/MsmqUtilities.cs
@@ -1,6 +1,7 @@
using System;
using System.Messaging;
using System.Net;
+using System.Net.NetworkInformation;
using System.Security.Principal;
using Common.Logging;
@@ -107,6 +108,46 @@ public static string GetFullPath(string value)
}
/// <summary>
+ /// Gets the name of the return address from the provided value.
+ /// If the target includes a machine name, uses the local machine name in the returned value
+ /// otherwise uses the local IP address in the returned value.
+ /// </summary>
+ /// <param name="value"></param>
+ /// <param name="target"></param>
+ /// <returns></returns>
+ public static string GetReturnAddress(string value, string target)
+ {
+ var machine = GetMachineNameFromLogicalName(target);
+
+ IPAddress ipAddress;
+
+ //see if the target is an IP address, if so, get our own local ip address
+ if (IPAddress.TryParse(machine, out ipAddress))
+ {
+ string myIp = null;
+
+ var networkInterfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
+ foreach(var ni in networkInterfaces)
+ if (ni.OperationalStatus == OperationalStatus.Up && ni.NetworkInterfaceType != NetworkInterfaceType.Loopback)
+ {
+ var ipProps = ni.GetIPProperties();
+ if (ipProps.UnicastAddresses.Count > 0)
+ {
+ myIp = ipProps.UnicastAddresses[1].Address.ToString();
+ break;
+ }
+ }
+
+ if (myIp == null)
+ myIp = "127.0.0.1";
+
+ return PREFIX_TCP + myIp + PRIVATE + GetQueueNameFromLogicalName(value);
+ }
+
+ return PREFIX + GetFullPathWithoutPrefix(value);
+ }
+
+ /// <summary>
/// Returns the full path without Format or direct os
/// from a '@' separated path.
/// </summary>
@@ -184,9 +225,11 @@ public static string GetIndependentAddressForQueue(MessageQueue q)
int directPrefixIndex = arr[0].IndexOf(DIRECTPREFIX);
if (directPrefixIndex >= 0)
- {
return queueName + '@' + arr[0].Substring(directPrefixIndex + DIRECTPREFIX.Length);
- }
+
+ int tcpPrefixIndex = arr[0].IndexOf(DIRECTPREFIX_TCP);
+ if (tcpPrefixIndex >= 0)
+ return queueName + '@' + arr[0].Substring(tcpPrefixIndex + DIRECTPREFIX_TCP.Length);
try
{
@@ -197,9 +240,7 @@ public static string GetIndependentAddressForQueue(MessageQueue q)
}
catch
{
- throw new Exception(string.Concat("MessageQueueException: '",
- DIRECTPREFIX, "' is missing. ",
- "FormatName='", q.FormatName, "'"));
+ throw new Exception("Could not translate format name to independent name: " + q.FormatName);
}
}
View
3  src/utils/NServiceBus.Utils.csproj
@@ -14,7 +14,6 @@
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
@@ -57,7 +56,7 @@
<Reference Include="Common.Logging, Version=1.1.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Common.Logging.dll</HintPath>
- <Private>False</Private>
+ <Private>True</Private>
</Reference>
<Reference Include="Interop.MSMQ, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Please sign in to comment.
Something went wrong with that request. Please try again.