Parse() public static method

public static Parse ( string address ) : MsmqAddress
address string
return MsmqAddress
Exemplo n.º 1
0
        public static void CheckQueue(string address)
        {
            var msmqAddress = MsmqAddress.Parse(address);
            var queuePath   = msmqAddress.PathWithoutPrefix;

            Logger.Debug($"Checking if queue exists: {queuePath}.");
            if (msmqAddress.IsRemote)
            {
                Logger.Info($"Since {address} is remote, the queue could not be verified. Make sure the queue exists and that the address and permissions are correct. Messages could end up in the dead letter queue if configured incorrectly.");
                return;
            }

            var path = msmqAddress.PathWithoutPrefix;

            try
            {
                if (MessageQueue.Exists(path))
                {
                    using (var messageQueue = new MessageQueue(path))
                    {
                        Logger.DebugFormat("Verified that the queue: [{0}] exists", queuePath);
                        WarnIfPublicAccess(messageQueue, LocalEveryoneGroupName);
                        WarnIfPublicAccess(messageQueue, LocalAnonymousLogonName);
                    }
                }
                else
                {
                    Logger.WarnFormat("Queue [{0}] does not exist", queuePath);
                }
            }
            catch (MessageQueueException ex)
            {
                Logger.Warn($"Unable to verify queue at address '{queuePath}'. Make sure the queue exists, and that the address is correct. Processing will still continue.", ex);
            }
        }
Exemplo n.º 2
0
        public Task Init(Func <MessageContext, Task> onMessage, Func <ErrorContext, Task <ErrorHandleResult> > onError, CriticalError criticalError, PushSettings settings)
        {
            peekCircuitBreaker    = new RepeatedFailuresOverTimeCircuitBreaker("MsmqPeek", TimeSpan.FromSeconds(30), ex => criticalError.Raise("Failed to peek " + settings.InputQueue, ex));
            receiveCircuitBreaker = new RepeatedFailuresOverTimeCircuitBreaker("MsmqReceive", TimeSpan.FromSeconds(30), ex => criticalError.Raise("Failed to receive from " + settings.InputQueue, ex));

            var inputAddress = MsmqAddress.Parse(settings.InputQueue);
            var errorAddress = MsmqAddress.Parse(settings.ErrorQueue);

            if (!string.Equals(inputAddress.Machine, RuntimeEnvironment.MachineName, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception($"MSMQ Dequeuing can only run against the local machine. Invalid inputQueue name '{settings.InputQueue}'.");
            }

            inputQueue = new MessageQueue(inputAddress.FullPath, false, true, QueueAccessMode.Receive);
            errorQueue = new MessageQueue(errorAddress.FullPath, false, true, QueueAccessMode.Send);

            if (settings.RequiredTransactionMode != TransportTransactionMode.None && !QueueIsTransactional())
            {
                throw new ArgumentException($"Queue must be transactional if you configure the endpoint to be transactional ({settings.InputQueue}).");
            }

            inputQueue.MessageReadPropertyFilter = DefaultReadPropertyFilter;

            if (settings.PurgeOnStartup)
            {
                inputQueue.Purge();
            }

            receiveStrategy = receiveStrategyFactory(settings.RequiredTransactionMode);

            receiveStrategy.Init(inputQueue, errorQueue, onMessage, onError, criticalError);

            return(TaskEx.CompletedTask);
        }
Exemplo n.º 3
0
        public static void CheckQueue(string address)
        {
            var msmqAddress = MsmqAddress.Parse(address);
            var queuePath   = msmqAddress.PathWithoutPrefix;

            Logger.Debug($"Checking if queue exists: {queuePath}.");

            var path = msmqAddress.PathWithoutPrefix;

            try
            {
                if (MessageQueue.Exists(path))
                {
                    using (var messageQueue = new MessageQueue(path))
                    {
                        Logger.DebugFormat("Verified that the queue: [{0}] existed", queuePath);

                        WarnIfPublicAccess(messageQueue);
                    }
                }
            }
            catch (MessageQueueException ex)
            {
                if (msmqAddress.IsRemote)
                {
                    Logger.Warn($"Unable to verify remote queue '{queuePath}'. Make sure the queue exists, and that the address is correct. Processing will still continue.", ex);
                    return;
                }

                Logger.Warn($"Unable to verify queue at address '{queuePath}'. Make sure the queue exists, and that the address is correct. Processing will still continue.", ex);
            }
        }
Exemplo n.º 4
0
        void CreateQueueIfNecessary(string address, string identity)
        {
            if (address == null)
            {
                return;
            }

            var msmqAddress = MsmqAddress.Parse(address);

            Logger.Debug($"Creating '{address}' if needed.");

            MessageQueue queue;

            if (MsmqUtilities.TryOpenQueue(msmqAddress, out queue) || MsmqUtilities.TryCreateQueue(msmqAddress, identity, settings.UseTransactionalQueues, out queue))
            {
                using (queue)
                {
                    Logger.Debug("Setting queue permissions.");

                    try
                    {
                        QueuePermissions.SetPermissionsForQueue(queue, identity);
                    }
                    catch (MessageQueueException ex)
                    {
                        Logger.Error($"Unable to set permissions for queue {queue.QueueName}", ex);
                    }
                }
            }
        }
Exemplo n.º 5
0
 public WorkerFeature()
 {
     DependsOn <DelayedDeliveryFeature>();
     Defaults(s =>
     {
         var distributorAddress                 = s.Get <string>("LegacyDistributor.Address");
         var distributorMsmqAddress             = MsmqAddress.Parse(distributorAddress);
         var distributorTimeoutQueue            = new MsmqAddress(distributorMsmqAddress.Queue + ".Timeouts", distributorMsmqAddress.Machine);
         var timeoutManagerAddressConfiguration = s.Get <TimeoutManagerAddressConfiguration>();
         timeoutManagerAddressConfiguration.Set(distributorTimeoutQueue.ToString());
     });
 }
Exemplo n.º 6
0
        void CreateQueueIfNecessary(string address, string identity)
        {
            var msmqAddress = MsmqAddress.Parse(address);

            Logger.Debug($"Creating '{address}' if needed.");

            if (msmqAddress.IsRemote)
            {
                Logger.Info($"'{address}' is a remote queue and won't be created");
                return;
            }

            var queuePath = msmqAddress.PathWithoutPrefix;

            if (MessageQueue.Exists(queuePath))
            {
                Logger.Debug($"'{address}' already exists");
                return;
            }

            try
            {
                using (var queue = MessageQueue.Create(queuePath, useTransactionalQueues))
                {
                    try
                    {
                        Logger.Debug("Setting queue permissions.");

                        QueuePermissions.SetPermissionsForQueue(queue, identity);
                    }
                    catch (MessageQueueException ex)
                    {
                        Logger.Error($"Unable to set permissions for queue {queue.QueueName}", ex);
                    }
                }
            }
            catch (MessageQueueException ex)
            {
                if (ex.MessageQueueErrorCode == MessageQueueErrorCode.QueueExists)
                {
                    //Solve the race condition problem when multiple endpoints try to create same queue (e.g. error queue).
                    return;
                }

                Logger.Error($"Could not create queue {msmqAddress}. Processing will still continue.", ex);
            }
        }
Exemplo n.º 7
0
        void CreateQueueIfNecessary(string address, string identity)
        {
            var msmqAddress = MsmqAddress.Parse(address);

            Logger.Debug($"Creating '{address}' if needed.");

            if (msmqAddress.IsRemote)
            {
                Logger.Info($"'{address}' is a remote queue and won't be created");
                return;
            }

            var queuePath = msmqAddress.PathWithoutPrefix;

            if (MessageQueue.Exists(queuePath))
            {
                Logger.Debug($"'{address}' already exists");
                return;
            }

            try
            {
                using (var queue = MessageQueue.Create(queuePath, useTransactionalQueues))
                {
                    Logger.Debug($"Created queue, path: [{queuePath}], identity: [{identity}], transactional: [{useTransactionalQueues}]");

                    try
                    {
                        queue.SetPermissions(identity, MessageQueueAccessRights.WriteMessage);
                        queue.SetPermissions(identity, MessageQueueAccessRights.ReceiveMessage);
                        queue.SetPermissions(identity, MessageQueueAccessRights.PeekMessage);

                        queue.SetPermissions(LocalAdministratorsGroupName, MessageQueueAccessRights.FullControl);
                    }
                    catch (MessageQueueException permissionException) when(permissionException.MessageQueueErrorCode == MessageQueueErrorCode.FormatNameBufferTooSmall)
                    {
                        Logger.Warn($"The name for queue '{queue.FormatName}' is too long for permissions to be applied. Please consider a shorter endpoint name.", permissionException);
                    }
                }
            }
            catch (MessageQueueException ex) when(ex.MessageQueueErrorCode == MessageQueueErrorCode.QueueExists)
            {
                //Solves the race condition problem when multiple endpoints try to create same queue (e.g. error queue).
            }
        }
Exemplo n.º 8
0
 public override string MakeCanonicalForm(string transportAddress)
 {
     return(MsmqAddress.Parse(transportAddress).ToString());
 }
Exemplo n.º 9
0
        void ExecuteTransportOperation(TransportTransaction transaction, UnicastTransportOperation transportOperation)
        {
            var message = transportOperation.Message;

            var destination        = transportOperation.Destination;
            var destinationAddress = MsmqAddress.Parse(destination);

            if (IsCombiningTimeToBeReceivedWithTransactions(
                    transaction,
                    transportOperation.RequiredDispatchConsistency,
                    transportOperation.DeliveryConstraints))
            {
                throw new Exception($"Failed to send message to address: {destinationAddress.Queue}@{destinationAddress.Machine}. Sending messages with a custom TimeToBeReceived is not supported on transactional MSMQ.");
            }

            try
            {
                using (var q = new MessageQueue(destinationAddress.FullPath, false, settings.UseConnectionCache, QueueAccessMode.Send))
                {
                    using (var toSend = MsmqUtilities.Convert(message, transportOperation.DeliveryConstraints))
                    {
                        toSend.UseDeadLetterQueue = settings.UseDeadLetterQueue;
                        toSend.UseJournalQueue    = settings.UseJournalQueue;
                        toSend.TimeToReachQueue   = settings.TimeToReachQueue;

                        string replyToAddress;

                        if (message.Headers.TryGetValue(Headers.ReplyToAddress, out replyToAddress))
                        {
                            toSend.ResponseQueue = new MessageQueue(MsmqAddress.Parse(replyToAddress).FullPath);
                        }

                        var label = GetLabel(message);

                        if (transportOperation.RequiredDispatchConsistency == DispatchConsistency.Isolated)
                        {
                            q.Send(toSend, label, GetIsolatedTransactionType());
                            return;
                        }

                        MessageQueueTransaction activeTransaction;
                        if (TryGetNativeTransaction(transaction, out activeTransaction))
                        {
                            q.Send(toSend, label, activeTransaction);
                            return;
                        }

                        q.Send(toSend, label, GetTransactionTypeForSend());
                    }
                }
            }
            catch (MessageQueueException ex)
            {
                if (ex.MessageQueueErrorCode == MessageQueueErrorCode.QueueNotFound)
                {
                    var msg = destination == null
                        ? "Failed to send message. Target address is null."
                        : $"Failed to send message to address: [{destination}]";

                    throw new QueueNotFoundException(destination, msg, ex);
                }

                ThrowFailedToSendException(destination, ex);
            }
            catch (Exception ex)
            {
                ThrowFailedToSendException(destination, ex);
            }
        }