示例#1
0
		public bool Execute()
		{
			Uri fromUri = _fromUriString.ToUri("The from URI was invalid");
			Uri toUri = _toUriString.ToUri("The to URI was invalid");

			IInboundTransport fromTransport = Program.Transports.GetTransport(fromUri);
			IOutboundTransport toTransport = Program.Transports.GetTransport(toUri);

			ITextBlock text = new TextBlock()
				.BeginBlock("Move messages from " + fromUri + " to " + toUri, "");

			int moveCount = 0;
			for (int i = 0; i < _count; i++)
			{
				fromTransport.Receive(receiveContext =>
					{
						return context =>
							{
								var moveContext = new MoveMessageSendContext(context);

								toTransport.Send(moveContext);

								text.BodyFormat("Message-Id: {0}", context.MessageId);

								moveCount++;
							};
					}, TimeSpan.Zero);
			}

			_log.Info(text);
			_log.InfoFormat("{0} message{1} moved from {2} to {3}", moveCount, moveCount == 1 ? "" : "s", fromUri, toUri);

			return true;
		}
示例#2
0
        void MoveMessageToErrorTransport(IReceiveContext context, Exception exception = null)
        {
            var moveContext = new MoveMessageSendContext(context);

            if (exception != null)
            {
                moveContext.SetHeader("MT-Fault-Message", exception.Message);
                moveContext.SetHeader("MT-Fault-StackTrace", exception.StackTrace);
            }

            moveContext.SetHeader("MT-Error-Host", Environment.MachineName);
            moveContext.SetHeader("MT-Error-Process", Process.GetCurrentProcess().ProcessName);

            Assembly entryAssembly = Assembly.GetEntryAssembly();

            if (entryAssembly != null)
            {
                AssemblyName assemblyName = entryAssembly.GetName();
                moveContext.SetHeader("MT-Error-Assembly", assemblyName.Name);
            }

            _errorTransport.Send(moveContext);

            string messageId = context.OriginalMessageId ?? context.MessageId;

            _tracker.MessageWasMovedToErrorQueue(messageId);

            Address.LogMoved(_errorTransport.Address, context.MessageId, "");
        }
示例#3
0
		public bool Execute()
		{
			Uri uri = _uriString.ToUri("The URI was invalid");

			IDuplexTransport transport = Program.Transports.GetTransport(uri);

			ITextBlock text = new TextBlock()
				.BeginBlock("Requeue messages to " + uri, "");


			int requeueCount = 0;
			for (int i = 0; i < _count; i++)
			{
				transport.Receive(receiveContext =>
					{
						return context =>
							{
								var moveContext = new MoveMessageSendContext(context);

								transport.Send(moveContext);

								text.BodyFormat("Message-Id: {0}", context.MessageId);

								requeueCount++;
							};
					}, TimeSpan.Zero);
			}

			_log.Info(text);
			_log.InfoFormat("{0} message{1} requeued to {2}", requeueCount, requeueCount == 1 ? "" : "s", uri);

			return true;
		}
示例#4
0
        public bool Execute()
        {
            Uri uri = _uriString.ToUri("The URI was invalid");

            IInboundTransport  inboundTransport  = Program.Transports.GetInboundTransport(uri);
            IOutboundTransport outboundTransport = Program.Transports.GetOutboundTransport(uri);

            ITextBlock text = new TextBlock()
                              .BeginBlock("Requeue messages to " + uri, "");


            int requeueCount = 0;

            for (int i = 0; i < _count; i++)
            {
                inboundTransport.Receive(receiveContext =>
                {
                    return(context =>
                    {
                        var moveContext = new MoveMessageSendContext(context);

                        outboundTransport.Send(moveContext);

                        text.BodyFormat("Message-Id: {0}", context.MessageId);

                        requeueCount++;
                    });
                }, 5.Seconds());
            }

            _log.Info(text);
            _log.InfoFormat("{0} message{1} requeued to {2}", requeueCount, requeueCount == 1 ? "" : "s", uri);

            return(true);
        }
示例#5
0
        public override bool Execute()
        {
            _log.InfoFormat("Moving messages from '{0}' to '{1}'", _fromUri, _toUri);

            IInboundTransport  fromTransport = GetInboundTransport(_fromUri);
            IOutboundTransport toTransport   = GetOutboundTransport(_toUri);

            int moveCount = 0;

            for (int i = 0; i < _count; i++)
            {
                fromTransport.Receive(receiveContext =>
                {
                    return(context =>
                    {
                        var moveContext = new MoveMessageSendContext(context);

                        toTransport.Send(moveContext);

                        _log.DebugFormat("Moving Message Id: {0}", context.MessageId);

                        moveCount++;
                    });
                }, 5.Seconds());
            }

            _log.InfoFormat("{0} message{1} moved from {2} to {3}", moveCount, moveCount == 1 ? "" : "s", _fromUri, _toUri);

            return(true);
        }
示例#6
0
        public bool Execute()
        {
            Uri fromUri = _fromUriString.ToUri("The from URI was invalid");
            Uri toUri   = _toUriString.ToUri("The to URI was invalid");

            IInboundTransport  fromTransport = Program.Transports.GetTransport(fromUri);
            IOutboundTransport toTransport   = Program.Transports.GetTransport(toUri);

            ITextBlock text = new TextBlock()
                              .BeginBlock("Move messages from " + fromUri + " to " + toUri, "");

            int moveCount = 0;

            for (int i = 0; i < _count; i++)
            {
                fromTransport.Receive(receiveContext =>
                {
                    return(context =>
                    {
                        var moveContext = new MoveMessageSendContext(context);

                        toTransport.Send(moveContext);

                        text.BodyFormat("Message-Id: {0}", context.MessageId);

                        moveCount++;
                    });
                }, TimeSpan.Zero);
            }

            _log.Info(text);
            _log.InfoFormat("{0} message{1} moved from {2} to {3}", moveCount, moveCount == 1 ? "" : "s", fromUri, toUri);

            return(true);
        }
示例#7
0
        void SaveMessageToInboundTransport(IReceiveContext context)
        {
            var moveContext = new MoveMessageSendContext(context);

            _transport.Send(moveContext);

            Address.LogReQueued(_transport.Address, context.MessageId, "");
        }
示例#8
0
        void MoveMessageToErrorTransport(IReceiveContext context)
        {
            var moveContext = new MoveMessageSendContext(context);

            _errorTransport.Send(moveContext);

            Address.LogMoved(_errorTransport.Address, context.MessageId, "");
        }
示例#9
0
        void MoveMessageToErrorTransport(IReceiveContext context)
        {
            var moveContext = new MoveMessageSendContext(context);

            _errorTransport.Send(moveContext);

            string messageId = context.OriginalMessageId ?? context.MessageId;

            _tracker.MessageWasMovedToErrorQueue(messageId);

            Address.LogMoved(_errorTransport.Address, context.MessageId, "");
        }
示例#10
0
        void MoveMessageToErrorTransport(IReceiveContext context)
        {
            var moveContext = new MoveMessageSendContext(context);

            _errorTransport.Send(moveContext);

            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("MOVE:{0}:{1}:{2}", Address, _errorTransport.Address, context.MessageId);
            }

            if (SpecialLoggers.Messages.IsInfoEnabled)
            {
                SpecialLoggers.Messages.InfoFormat("MOVE:{0}:{1}:{2}", Address, _errorTransport.Address, context.MessageId);
            }
        }
        /// <summary>
        /// May throw a timeout exception if a message with the given id cannot be found.
        /// </summary>
        /// <param name="messageId"></param>
        public void ReturnMessageToSourceQueue(string messageId, IReceiveContext context)
        {
            try
            {
                var query      = context.DestinationAddress.Query;
                var errorQueue = context.DestinationAddress.OriginalString.Replace(query, "") + "_error";

                Uri fromUri = new Uri(errorQueue);
                Uri toUri   = context.DestinationAddress;

                IInboundTransport  fromTransport = Transports.GetInboundTransport(fromUri);
                IOutboundTransport toTransport   = Transports.GetOutboundTransport(toUri);

                fromTransport.Receive(receiveContext =>
                {
                    if (receiveContext.MessageId == messageId)
                    {
                        return(ctx =>
                        {
                            var moveContext = new MoveMessageSendContext(ctx);
                            toTransport.Send(moveContext);
                        });
                    }

                    return(null);
                }, 5.Seconds());

                Console.WriteLine("Success.");
            }
            catch (MessageQueueException ex)
            {
                if (ex.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout)
                {
                    Console.WriteLine(NoMessageFoundErrorFormat, context.Id);

                    foreach (var m in queue.GetAllMessages())
                    {
                        var tm = TransportMessageHeaders.Create(m.Extension);

                        if (tm[""] != null)
                        {
                            //if (messageId != tm[""])
                            //    continue;

                            Console.WriteLine("Found message - going to return to queue.");

                            using (var tx = new TransactionScope())
                            {
                                using (var q = new MessageQueue(new EndpointAddress(tm[""]).Path))
                                    q.Send(m, MessageQueueTransactionType.Automatic);

                                queue.ReceiveByLookupId(MessageLookupAction.Current, m.LookupId,
                                                        MessageQueueTransactionType.Automatic);

                                tx.Complete();
                            }

                            Console.WriteLine("Success.");
                            //scope.Complete();

                            return;
                        }
                    }
                }
            }
            //}
        }
示例#12
0
		/// <summary>
		/// May throw a timeout exception if a message with the given id cannot be found.
		/// </summary>
		/// <param name="messageId"></param>
		public void ReturnMessageToSourceQueue(string messageId, IReceiveContext context)
		{
			try
			{
				var query = context.DestinationAddress.Query;
				var errorQueue = context.DestinationAddress.OriginalString.Replace(query, "") + "_error";

				Uri fromUri = new Uri(errorQueue);
				Uri toUri = context.DestinationAddress;

				IInboundTransport fromTransport = Transports.GetInboundTransport(fromUri);
				IOutboundTransport toTransport = Transports.GetOutboundTransport(toUri);

				fromTransport.Receive(receiveContext =>
				{
					if (receiveContext.MessageId == messageId)
					{
						return ctx =>
						{
							var moveContext = new MoveMessageSendContext(ctx);
							toTransport.Send(moveContext);
						};
					}

					return null;

				}, 5.Seconds());

				Console.WriteLine("Success.");
			}
			catch (MessageQueueException ex)
			{
				if (ex.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout)
				{
					Console.WriteLine(NoMessageFoundErrorFormat, context.Id);

					foreach (var m in queue.GetAllMessages())
					{
						var tm = TransportMessageHeaders.Create(m.Extension);

						if (tm[""] != null)
						{
							//if (messageId != tm[""])
							//    continue;

							Console.WriteLine("Found message - going to return to queue.");

							using (var tx = new TransactionScope())
							{
								using (var q = new MessageQueue(new EndpointAddress(tm[""]).Path))
									q.Send(m, MessageQueueTransactionType.Automatic);

								queue.ReceiveByLookupId(MessageLookupAction.Current, m.LookupId,
														MessageQueueTransactionType.Automatic);

								tx.Complete();
							}

							Console.WriteLine("Success.");
							//scope.Complete();

							return;
						}
					}
				}
			}
			//}
		}