ReturnMessageToSourceQueue() public méthode

May throw a timeout exception if a message with the given id cannot be found.
public ReturnMessageToSourceQueue ( string messageId ) : void
messageId string
Résultat void
Exemple #1
0
        static void Main(string[] args)
        {
            var errorManager = new ErrorManager();

            string inputQueue = null;
            string messageId  = null;

            if (args != null && args.Length > 0)
            {
                inputQueue = args[0];
            }

            if (args != null && args.Length > 1)
            {
                messageId = args[1];
            }

            if (inputQueue == null)
            {
                Console.WriteLine("Please enter the error queue you would like to use:");
                inputQueue = Console.ReadLine();
            }

            if (messageId == null)
            {
                Console.WriteLine("Please enter the id of the message you'd like to return to its source queue, or 'all' to do so for all messages in the queue.");
                messageId = Console.ReadLine();

                Console.WriteLine("Attempting to return message to source queue. Please stand by.");
            }

            errorManager.InputQueue = Address.Parse(inputQueue);

            try
            {
                if (messageId == "all")
                {
                    errorManager.ReturnAll();
                }
                else
                {
                    errorManager.ReturnMessageToSourceQueue(messageId);
                }

                if (args == null || args.Length == 0)
                {
                    Console.WriteLine("Press 'Enter' to exit.");
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not return message to source queue. Reason: " + e.Message);
                Console.WriteLine(e.StackTrace);

                Console.WriteLine("\nPress 'Enter' to exit.");
                Console.ReadLine();
            }
        }
Exemple #2
0
    public override void MoveErrorMessageToOriginQueue(QueueItem itm) {
      if( string.IsNullOrEmpty(itm.Id) )
        throw new ArgumentException("MessageId can not be null or empty");

      if( itm.Queue.Type != QueueType.Error )
        throw new ArgumentException("Queue is not of type Error, " + itm.Queue.Type);

      var mgr = new ErrorManager();

      // TODO:
      // Check if Clustered Queue, due if Clustered && NonTransactional, then Error

      mgr.InputQueue = Address.Parse(itm.Queue.Name);

      mgr.ReturnMessageToSourceQueue(itm.Id);
    }
        public override void MoveErrorMessageToOriginQueue(QueueItem itm)
        {
            if (string.IsNullOrEmpty(itm.Id))
            {
                throw new ArgumentException("MessageId can not be null or empty");
            }

            if (itm.Queue.Type != QueueType.Error)
            {
                throw new ArgumentException("Queue is not of type Error, " + itm.Queue.Type);
            }

            try {
                var mgr = new ErrorManager();

                mgr.InputQueue = Address.Parse(itm.Queue.Name);

                mgr.ReturnMessageToSourceQueue(itm.Id);
            } catch (Exception e) {
                throw new Exception("Failed to Move Messages from Error Queue '{0}' to Origin".With(itm.Queue.Name), e);
            }
        }
    static void Main(string[] args)
    {
        var errorManager = new ErrorManager();

        string inputQueue = null;
        string messageId  = null;

        if (args != null && args.Length > 0)
        {
            inputQueue = args[0];
        }

        if (args != null && args.Length > 1)
        {
            messageId = args[1];
        }

        var script = true;

        if (inputQueue == null)
        {
            Console.WriteLine("NServiceBus ReturnToSource for MSMQ");
            Console.WriteLine("by Particular Software Ltd. \n");

            Console.WriteLine("Please enter the error queue you would like to use:");
            inputQueue = Console.ReadLine();
            if (string.IsNullOrWhiteSpace(inputQueue))
            {
                Console.WriteLine("No error queue specified");
                Console.WriteLine("\nPress 'Enter' to exit.");
                Console.ReadLine();
                return;
            }
            script = false;
        }

        var errorQueueAddress = MsmqAddress.Parse(inputQueue);

        if (!IsLocalIpAddress(errorQueueAddress.Machine))
        {
            Console.WriteLine("Input queue [{0}] resides on a remote machine: [{1}].", errorQueueAddress.Queue, errorQueueAddress.Machine);
            Console.WriteLine("Due to networking load, it is advised to refrain from using ReturnToSourceQueue on a remote error queue, unless the error queue resides on a clustered machine.");
            if (!script)
            {
                Console.WriteLine(
                    "Press 'y' if the error queue resides on a Clustered Machine, otherwise press any key to exit.");
                if (Console.ReadKey().Key.ToString().ToLower() != "y")
                {
                    return;
                }
            }
            Console.WriteLine(string.Empty);
            errorManager.ClusteredQueue = true;
        }

        if (messageId == null)
        {
            Console.WriteLine("Please enter the id of the message you'd like to return to its source queue, or 'all' to do so for all messages in the queue.");
            messageId = Console.ReadLine();
        }

        errorManager.InputQueue = errorQueueAddress;
        Console.WriteLine("Attempting to return message to source queue. Queue: [{0}], message id: [{1}]. Please stand by.",
                          errorQueueAddress, messageId);

        try
        {
            if (messageId == "all")
            {
                errorManager.ReturnAll();
            }
            else
            {
                errorManager.ReturnMessageToSourceQueue(messageId);
            }

            if (args == null || args.Length == 0)
            {
                Console.WriteLine("Press 'Enter' to exit.");
                Console.ReadLine();
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("Could not return message to source queue. Reason: " + e.Message);
            Console.WriteLine(e.StackTrace);

            Console.WriteLine("\nPress 'Enter' to exit.");
            Console.ReadLine();
        }
    }
    static void Main(string[] args)
    {
        var errorManager = new ErrorManager();

        string inputQueue = null;
        string messageId = null;

        if (args != null && args.Length > 0)
            inputQueue = args[0];

        if (args != null && args.Length > 1)
            messageId = args[1];

        var script = true;

        if (inputQueue == null)
        {
            Console.WriteLine("NServiceBus ReturnToSource for MSMQ");
            Console.WriteLine("by Particular Software Ltd. \n");

            Console.WriteLine("Please enter the error queue you would like to use:");
            inputQueue = Console.ReadLine();
            if (string.IsNullOrWhiteSpace(inputQueue))
            {
                Console.WriteLine("No error queue specified");
                Console.WriteLine("\nPress 'Enter' to exit.");
                Console.ReadLine();
                return;
            }
            script = false;
        }

        var errorQueueAddress = MsmqAddress.Parse(inputQueue);

        if (!IsLocalIpAddress(errorQueueAddress.Machine))
        {
            Console.WriteLine("Input queue [{0}] resides on a remote machine: [{1}].", errorQueueAddress.Queue, errorQueueAddress.Machine);
            Console.WriteLine("Due to networking load, it is advised to refrain from using ReturnToSourceQueue on a remote error queue, unless the error queue resides on a clustered machine.");
            if (!script)
            {
                Console.WriteLine(
                    "Press 'y' if the error queue resides on a Clustered Machine, otherwise press any key to exit.");
                if (Console.ReadKey().Key.ToString().ToLower() != "y")
                    return;
            }
            Console.WriteLine(string.Empty);
            errorManager.ClusteredQueue = true;
        }

        if (messageId == null)
        {
            Console.WriteLine("Please enter the id of the message you'd like to return to its source queue, or 'all' to do so for all messages in the queue.");
            messageId = Console.ReadLine();
        }

        errorManager.InputQueue = errorQueueAddress;
        Console.WriteLine("Attempting to return message to source queue. Queue: [{0}], message id: [{1}]. Please stand by.",
            errorQueueAddress, messageId);

        try
        {
            if (messageId == "all")
                errorManager.ReturnAll();
            else
                errorManager.ReturnMessageToSourceQueue(messageId);

            if (args == null || args.Length == 0)
            {
                Console.WriteLine("Press 'Enter' to exit.");
                Console.ReadLine();
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("Could not return message to source queue. Reason: " + e.Message);
            Console.WriteLine(e.StackTrace);

            Console.WriteLine("\nPress 'Enter' to exit.");
            Console.ReadLine();
        }
    }