public static void CreateQueueIfNecessary(Address address, string account)
{
if (address == null)
return;
var q = GetFullPathWithoutPrefix(address);
var isRemote = address.Machine != Environment.MachineName.ToLower();
if (isRemote)
{
_logger.Debug("Queue is on remote machine.");
_logger.Debug("If this does not succeed (like if the remote machine is disconnected), processing will continue.");
}
_logger.Debug(string.Format("Checking if queue exists: {0}.", address));
try
{
if (MessageQueue.Exists(q))
{
_logger.Debug("Queue exists, going to set permissions.");
SetPermissionsForQueue(q, accountToBeAssignedQueuePermissions ?? account);
return;
}
_logger.Warn("Queue " + q + " does not exist.");
_logger.Debug("Going to create queue: " + q);
CreateQueue(q, account);
}
catch (MessageQueueException ex)
{
if (isRemote && (ex.MessageQueueErrorCode == MessageQueueErrorCode.IllegalQueuePathName))
{
return;
}
_logger.Error(string.Format("Could not create queue {0} or check its existence. Processing will still continue.", address), ex);
}
catch (Exception ex)
{
_logger.Error(string.Format("Could not create queue {0} or check its existence. Processing will still continue.", address), ex);
}
}