NServiceBus.QueuePermissions.CheckQueue C# (CSharp) Method

CheckQueue() public static method

public static CheckQueue ( string address ) : void
address string
return void
        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);
            }
        }

Usage Example

Example #1
0
        public override TransportReceiveInfrastructure ConfigureReceiveInfrastructure()
        {
            new CheckMachineNameForComplianceWithDtcLimitation().Check();

            MsmqScopeOptions scopeOptions;

            if (!settings.TryGet(out scopeOptions))
            {
                scopeOptions = new MsmqScopeOptions();
            }

            var msmqSettings = settings.Get <MsmqSettings>();

            return(new TransportReceiveInfrastructure(
                       () => new MessagePump(guarantee => SelectReceiveStrategy(guarantee, scopeOptions.TransactionOptions)),
                       () => new MsmqQueueCreator(msmqSettings.UseTransactionalQueues),
                       () =>
            {
                var bindings = settings.Get <QueueBindings>();

                foreach (var address in bindings.ReceivingAddresses)
                {
                    QueuePermissions.CheckQueue(address);
                }
                return Task.FromResult(StartupCheckResult.Success);
            }));
        }
All Usage Examples Of NServiceBus.QueuePermissions::CheckQueue