Esempio n. 1
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, "");
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        void MoveMessageToErrorTransport(IReceiveContext context)
        {
            var moveContext = new MoveMessageSendContext(context);

            _errorTransport.Send(moveContext);

            Address.LogMoved(_errorTransport.Address, context.MessageId, "");
        }
        void SendMessage()
        {
            var context = new SendContext <DeleteMessage>(new DeleteMessage());

            context.SetBodyWriter(stream => _serializer.Serialize(stream, context));

            _transport.Send(context);
        }
Esempio n. 7
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, "");
        }
Esempio n. 8
0
        public bool Execute()
        {
            Uri uri = _uriString.ToUri("The from URI was invalid");

            AbsolutePathName fullPath = PathName.GetAbsolutePathName(_name, Environment.CurrentDirectory);

            _log.DebugFormat("Using output path name: {0}", fullPath);

            string directoryName = Path.GetDirectoryName(fullPath.GetPath());

            if (!System.IO.Directory.Exists(directoryName))
            {
                System.IO.Directory.CreateDirectory(directoryName);
            }

            IOutboundTransport toTransport = Program.Transports.GetOutboundTransport(uri);

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

            string[] files =
                System.IO.Directory.GetFiles(directoryName, fullPath.GetName() + "*.msg", SearchOption.TopDirectoryOnly)
                .OrderBy(x => x).ToArray();

            int loadCount = 0;

            for (int i = 0; i < files.Length && loadCount < _count; i++)
            {
                string file = files[i];

                string fileName = Path.Combine(directoryName, file);

                text.BodyFormat("Message File: {0}", file);

                ISendContext context = LoadMessageFromFile(fileName);

                toTransport.Send(context);

                if (_remove)
                {
                    System.IO.File.Delete(fileName);
                }

                loadCount++;
            }

            _log.Info(text.ToString());

            return(true);
        }
Esempio n. 9
0
        public override bool Execute()
        {
            Uri uri = _uri.ToUri("The from URI was invalid");

            AbsolutePathName fullPath = PathName.GetAbsolutePathName(_sourcePath, Environment.CurrentDirectory);

            _log.DebugFormat("Using output path name: {0}", fullPath);

            string directoryName = Path.GetDirectoryName(fullPath.GetPath());

            if (!System.IO.Directory.Exists(directoryName))
            {
                System.IO.Directory.CreateDirectory(directoryName);
            }

            IOutboundTransport toTransport = GetOutboundTransport(_uri);

            _log.InfoFormat("Loading messages from '{0}' to {1}", _sourcePath, _uri);

            string[] files =
                System.IO.Directory.GetFiles(directoryName, fullPath.GetName() + "*.msg", SearchOption.TopDirectoryOnly)
                .OrderBy(x => x).ToArray();

            int loadCount = 0;

            for (int i = 0; i < files.Length && loadCount < _count; i++)
            {
                string file = files[i];

                string fileName = Path.Combine(directoryName, file);

                _log.DebugFormat("Message-Id: '{0}'", file);

                ISendContext context = LoadMessageFromFile(fileName);

                toTransport.Send(context);

                if (_remove)
                {
                    System.IO.File.Delete(fileName);
                }

                loadCount++;
            }

            _log.InfoFormat("Loading messages from '{0}' to {1}", _sourcePath, _uri);

            return(true);
        }
Esempio n. 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);
            }
        }
        public void TransportSendAndReceive()
        {
            using (var management = new RabbitMqEndpointManagement(_queue))
            {
                management.BindQueue(_queue.Name, _exchange.Name, ExchangeType.Fanout, "", null);
            }

            IOutboundTransport t = _factory.BuildOutbound(new TransportSettings(_exchange));
            var context          = new SendContext <string>("dru");

            context.SetBodyWriter(stream =>
            {
                byte[] buffer = Encoding.UTF8.GetBytes(context.Message);
                stream.Write(buffer, 0, buffer.Length);
            });
            t.Send(context);

            IInboundTransport i = _factory.BuildInbound(new TransportSettings(_queue));

            i.Receive(s =>
            {
                return(ss =>
                {
                    string name;
                    using (var stream = new MemoryStream())
                    {
                        ss.CopyBodyTo(stream);

                        name = Encoding.UTF8.GetString(stream.ToArray());
                    }

                    Assert.AreEqual("dru", name);
                    Console.WriteLine(name);
                });
            }, 1.Minutes());
        }
        /// <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;
                        }
                    }
                }
            }
            //}
        }