コード例 #1
0
ファイル: QueueRetrieval.cs プロジェクト: ngbrown/EasyNetQ
        public IEnumerable<string> GetMessagesFromQueue(QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParamters(parameters))
            using (var channel = connection.CreateModel())
            {
                try
                {
                    channel.QueueDeclarePassive(parameters.QueueName);
                }
                catch (OperationInterruptedException exception)
                {
                    Console.WriteLine(exception.Message);
                    yield break;
                }

                var count = 0;
                while (++count < parameters.NumberOfMessagesToRetrieve)
                {
                    var basicGetResult = channel.BasicGet(parameters.QueueName, noAck: parameters.Purge);
                    if (basicGetResult == null) break; // no more messages on the queue

                    yield return Encoding.UTF8.GetString(basicGetResult.Body);
                }
            }
        }
コード例 #2
0
ファイル: QueueRetrieval.cs プロジェクト: tzaavi/EasyNetQ
        public IEnumerable <string> GetMessagesFromQueue(QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParamters(parameters))
                using (var channel = connection.CreateModel())
                {
                    try
                    {
                        channel.QueueDeclarePassive(parameters.QueueName);
                    }
                    catch (OperationInterruptedException exception)
                    {
                        Console.WriteLine(exception.Message);
                        yield break;
                    }

                    var count = 0;
                    while (++count < parameters.NumberOfMessagesToRetrieve)
                    {
                        var basicGetResult = channel.BasicGet(parameters.QueueName, noAck: parameters.Purge);
                        if (basicGetResult == null)
                        {
                            break;                     // no more messages on the queue
                        }
                        yield return(Encoding.UTF8.GetString(basicGetResult.Body));
                    }
                }
        }
コード例 #3
0
        public void Write(IEnumerable<HosepipeMessage> messages, QueueParameters parameters)
        {
            var count = 0;
            foreach (var message in messages)
            {
                var uniqueFileName = SanitiseQueueName(parameters.QueueName) + "." + count.ToString();

                var bodyPath = Path.Combine(parameters.MessageFilePath, uniqueFileName + ".message.txt");
                var propertiesPath = Path.Combine(parameters.MessageFilePath, uniqueFileName + ".properties.txt");
                var infoPath = Path.Combine(parameters.MessageFilePath, uniqueFileName + ".info.txt");
                
                if(File.Exists(bodyPath))
                {
                    Console.WriteLine("Overwriting existing messsage file: {0}", bodyPath);
                }
                try
                {
                    File.WriteAllText(bodyPath, message.Body);
                    File.WriteAllText(propertiesPath, Newtonsoft.Json.JsonConvert.SerializeObject(message.Properties));
                    File.WriteAllText(infoPath, Newtonsoft.Json.JsonConvert.SerializeObject(message.Info));
                }
                catch (DirectoryNotFoundException)
                {
                    throw new EasyNetQHosepipeException(
                        string.Format("Directory '{0}' does not exist", parameters.MessageFilePath));
                }
                count++;
            }
        }
コード例 #4
0
        public void Write(IEnumerable <HosepipeMessage> messages, QueueParameters parameters)
        {
            var count = 0;

            foreach (var message in messages)
            {
                var uniqueFileName = SanitiseQueueName(parameters.QueueName) + "." + count.ToString();

                var bodyPath       = Path.Combine(parameters.MessageFilePath, uniqueFileName + ".message.txt");
                var propertiesPath = Path.Combine(parameters.MessageFilePath, uniqueFileName + ".properties.txt");
                var infoPath       = Path.Combine(parameters.MessageFilePath, uniqueFileName + ".info.txt");

                if (File.Exists(bodyPath))
                {
                    Console.WriteLine("Overwriting existing messsage file: {0}", bodyPath);
                }
                try
                {
                    File.WriteAllText(bodyPath, message.Body);
                    File.WriteAllText(propertiesPath, Newtonsoft.Json.JsonConvert.SerializeObject(message.Properties));
                    File.WriteAllText(infoPath, Newtonsoft.Json.JsonConvert.SerializeObject(message.Info));
                }
                catch (DirectoryNotFoundException)
                {
                    throw new EasyNetQHosepipeException(
                              string.Format("Directory '{0}' does not exist", parameters.MessageFilePath));
                }
                count++;
            }
        }
コード例 #5
0
ファイル: FileMessageWriter.cs プロジェクト: y2ket/EasyNetQ
        public void Write(IEnumerable <HosepipeMessage> messages, QueueParameters parameters)
        {
            if (!Directory.Exists(parameters.MessagesOutputDirectory))
            {
                Console.WriteLine("Creating messages output directory: {0}", parameters.MessagesOutputDirectory);
                Directory.CreateDirectory(parameters.MessagesOutputDirectory);
            }

            var count = 0;

            foreach (var message in messages)
            {
                var uniqueFileName = SanitiseQueueName(parameters.QueueName) + "." + count;

                var bodyPath       = Path.Combine(parameters.MessagesOutputDirectory, uniqueFileName + ".message.txt");
                var propertiesPath = Path.Combine(parameters.MessagesOutputDirectory, uniqueFileName + ".properties.txt");
                var infoPath       = Path.Combine(parameters.MessagesOutputDirectory, uniqueFileName + ".info.txt");

                if (File.Exists(bodyPath))
                {
                    Console.WriteLine("Overwriting existing message file: {0}", bodyPath);
                }

                File.WriteAllText(bodyPath, message.Body);
                File.WriteAllText(propertiesPath, Newtonsoft.Json.JsonConvert.SerializeObject(message.Properties));
                File.WriteAllText(infoPath, Newtonsoft.Json.JsonConvert.SerializeObject(message.Info));

                count++;
            }
        }
コード例 #6
0
ファイル: QueueInsertion.cs プロジェクト: stepaside/EasyNetQ
        public void PublishMessagesToQueue(IEnumerable <string> messages, QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParamters(parameters))
                using (var channel = connection.CreateModel())
                {
                    try
                    {
                        channel.QueueDeclarePassive(parameters.QueueName);
                    }
                    catch (OperationInterruptedException exception)
                    {
                        Console.WriteLine(exception.Message);
                        return;
                    }

                    foreach (var message in messages)
                    {
                        var body       = Encoding.UTF8.GetBytes(message);
                        var properties = channel.CreateBasicProperties();

                        // take advantage of the fact that every AMQP queue binds to the default ("")
                        // queue using its name as the routing key
                        channel.BasicPublish("", parameters.QueueName, properties, body);
                    }
                }
        }
コード例 #7
0
ファイル: ErrorRetry.cs プロジェクト: richard-green/EasyNetQ
        public void RepublishError(Error error, QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParamters(parameters))
            using (var model = connection.CreateModel())
            {
                try
                {
                    if (error.Exchange != string.Empty)
                    {
                        model.ExchangeDeclarePassive(error.Exchange);
                    }

                    var properties = model.CreateBasicProperties();
                    error.BasicProperties.CopyTo(properties);

                    var body = Encoding.UTF8.GetBytes(error.Message);

                    model.BasicPublish(error.Exchange, error.RoutingKey, properties, body);
                }
                catch (OperationInterruptedException)
                {
                    Console.WriteLine("The exchange, '{0}', described in the error message does not exist on '{1}', '{2}'",
                        error.Exchange, parameters.HostName, parameters.VHost);
                }
            }
        }
コード例 #8
0
        public static IConnection FromParameters(QueueParameters parameters)
        {
            var connectionFactory = new ConnectionFactory
            {
                HostName    = parameters.HostName,
                VirtualHost = parameters.VHost,
                UserName    = parameters.Username,
                Password    = parameters.Password,
                Port        = parameters.HostPort
            };

            try
            {
                return(connectionFactory.CreateConnection());
            }
            catch (BrokerUnreachableException)
            {
                throw new EasyNetQHosepipeException(string.Format(
                                                        "The broker at '{0}{2}' VirtualHost '{1}', is unreachable. This message can also be caused " +
                                                        "by incorrect credentials.",
                                                        parameters.HostName,
                                                        parameters.VHost,
                                                        parameters.HostPort == -1 ? string.Empty: ":" + parameters.HostPort));
            }
        }
コード例 #9
0
ファイル: MessageReader.cs プロジェクト: xw-fighting/EasyNetQ
        public IEnumerable <HosepipeMessage> ReadMessages(QueueParameters parameters, string messageName)
        {
            if (!Directory.Exists(parameters.MessageFilePath))
            {
                Console.WriteLine("Directory '{0}' does not exist", parameters.MessageFilePath);
                yield break;
            }

            var bodyPattern = (messageName ?? "*") + ".*.message.txt";

            foreach (var file in Directory.GetFiles(parameters.MessageFilePath, bodyPattern))
            {
                const string messageTag         = ".message.";
                var          directoryName      = Path.GetDirectoryName(file);
                var          fileName           = Path.GetFileName(file);
                var          propertiesFileName = Path.Combine(directoryName, fileName.Replace(messageTag, ".properties."));
                var          infoFileName       = Path.Combine(directoryName, fileName.Replace(messageTag, ".info."));

                var body = File.ReadAllText(file);

                var propertiesJson = File.ReadAllText(propertiesFileName);
                var properties     = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageProperties>(propertiesJson);

                var infoJson = File.ReadAllText(infoFileName);
                var info     = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageReceivedInfo>(infoJson);

                yield return(new HosepipeMessage(body, properties, info));
            }
        }
コード例 #10
0
        public IEnumerable<HosepipeMessage> ReadMessages(QueueParameters parameters, string messageName)
        {
            if (!Directory.Exists(parameters.MessageFilePath))
            {
                Console.WriteLine("Directory '{0}' does not exist", parameters.MessageFilePath);
                yield break;
            }

            var bodyPattern = (messageName ?? "*") + ".*.message.txt";

            foreach (var file in Directory.GetFiles(parameters.MessageFilePath, bodyPattern))
            {
                var propertiesFileName = file.Replace("message", "properties");
                var infoFileName = file.Replace("message", "info");

                var body = File.ReadAllText(file);

                var propertiesJson = File.ReadAllText(propertiesFileName);
                var properties = Newtonsoft.Json.JsonConvert.DeserializeObject<MessageProperties>(propertiesJson);

                var infoJson = File.ReadAllText(infoFileName);
                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<MessageReceivedInfo>(infoJson);

                yield return new HosepipeMessage(body, properties, info);
            }
        }
コード例 #11
0
ファイル: QueueInsertion.cs プロジェクト: ngbrown/EasyNetQ
        public void PublishMessagesToQueue(IEnumerable<string> messages, QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParamters(parameters))
            using (var channel = connection.CreateModel())
            {
                try
                {
                    channel.QueueDeclarePassive(parameters.QueueName);
                }
                catch (OperationInterruptedException exception)
                {
                    Console.WriteLine(exception.Message);
                    return;
                }

                foreach (var message in messages)
                {
                    var body = Encoding.UTF8.GetBytes(message);
                    var properties = channel.CreateBasicProperties();

                    // take advantage of the fact that every AMQP queue binds to the default ("")
                    // queue using its name as the routing key
                    channel.BasicPublish("", parameters.QueueName, properties, body);
                }
            }
        }
コード例 #12
0
ファイル: QueueRetrieval.cs プロジェクト: hippasus/EasyNetQ
        public IEnumerable<HosepipeMessage> GetMessagesFromQueue(QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParamters(parameters))
            using (var channel = connection.CreateModel())
            {
                try
                {
                    channel.QueueDeclarePassive(parameters.QueueName);
                }
                catch (OperationInterruptedException exception)
                {
                    Console.WriteLine(exception.Message);
                    yield break;
                }

                var count = 0;
                while (count++ < parameters.NumberOfMessagesToRetrieve)
                {
                    var basicGetResult = channel.BasicGet(parameters.QueueName, noAck: parameters.Purge);
                    if (basicGetResult == null) break; // no more messages on the queue

                    var properties = new MessageProperties(basicGetResult.BasicProperties);
                    var info = new MessageReceivedInfo(
                        "hosepipe",
                        basicGetResult.DeliveryTag,
                        basicGetResult.Redelivered,
                        basicGetResult.Exchange,
                        basicGetResult.RoutingKey,
                        parameters.QueueName);

                    yield return new HosepipeMessage(errorMessageSerializer.Serialize(basicGetResult.Body), properties, info);
                }
            }
        }
コード例 #13
0
        public void RepublishError(Error error, QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParamters(parameters))
                using (var model = connection.CreateModel())
                {
                    try
                    {
                        if (error.Exchange != string.Empty)
                        {
                            model.ExchangeDeclarePassive(error.Exchange);
                        }

                        var properties = model.CreateBasicProperties();
                        error.BasicProperties.CopyTo(properties);

                        var body = Encoding.UTF8.GetBytes(error.Message);

                        model.BasicPublish(error.Exchange, error.RoutingKey, properties, body);
                    }
                    catch (OperationInterruptedException)
                    {
                        Console.WriteLine("The exchange, '{0}', described in the error message does not exist on '{1}', '{2}'",
                                          error.Exchange, parameters.HostName, parameters.VHost);
                    }
                }
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: stepaside/EasyNetQ
        public void Start(string[] args)
        {
            var arguments = argParser.Parse(args);

            var results   = new StringBuilder();
            var succeeded = true;
            Func <string, Action> messsage = m => () =>
            {
                results.AppendLine(m);
                succeeded = false;
            };

            var parameters = new QueueParameters();

            arguments.WithKey("s", a => parameters.HostName        = a.Value);
            arguments.WithKey("v", a => parameters.VHost           = a.Value);
            arguments.WithKey("u", a => parameters.Username        = a.Value);
            arguments.WithKey("p", a => parameters.Password        = a.Value);
            arguments.WithKey("o", a => parameters.MessageFilePath = a.Value);
            arguments.WithTypedKeyOptional <int>("n", a => parameters.NumberOfMessagesToRetrieve = int.Parse(a.Value))
            .FailWith(messsage("Invalid number of messages to retrieve"));

            try
            {
                arguments.At(0, "dump", () => arguments.WithKey("q", a =>
                {
                    parameters.QueueName = a.Value;
                    Dump(parameters);
                }).FailWith(messsage("No Queue Name given")));

                arguments.At(0, "insert", () => arguments.WithKey("q", a =>
                {
                    parameters.QueueName = a.Value;
                    Insert(parameters);
                }).FailWith(messsage("No Queue Name given")));

                arguments.At(0, "err", () => ErrorDump(parameters));

                arguments.At(0, "retry", () => Retry(parameters));

                arguments.At(0, "?", PrintUsage);

                // print usage if there are no arguments
                arguments.At(0, a => {}).FailWith(PrintUsage);
            }
            catch (EasyNetQHosepipeException easyNetQHosepipeException)
            {
                Console.WriteLine("Operation Failed:");
                Console.WriteLine(easyNetQHosepipeException.Message);
            }

            if (!succeeded)
            {
                Console.WriteLine("Operation failed");
                Console.Write(results.ToString());
                Console.WriteLine();
                PrintUsage();
            }
        }
コード例 #15
0
 private void ErrorDump(QueueParameters parameters)
 {
     if (parameters.QueueName == null)
     {
         parameters.QueueName = conventions.ErrorQueueNamingConvention(null);
     }
     Dump(parameters);
 }
コード例 #16
0
ファイル: ErrorRetry.cs プロジェクト: EasyNetQ/EasyNetQ
 public void RetryErrors(IEnumerable<HosepipeMessage> rawErrorMessages, QueueParameters parameters)
 {
     foreach (var rawErrorMessage in rawErrorMessages)
     {
         var error = serializer.BytesToMessage<Error>(errorMessageSerializer.Deserialize(rawErrorMessage.Body));
         RepublishError(error, parameters);
     }
 }
コード例 #17
0
ファイル: Program.cs プロジェクト: zhangbo27/EasyNetQ
 private void ErrorDump(QueueParameters parameters)
 {
     if (parameters.QueueName == null)
     {
         parameters.QueueName = conventions.ErrorQueueNamingConvention(new MessageReceivedInfo());
     }
     Dump(parameters);
 }
コード例 #18
0
 public void RetryErrors(IEnumerable <HosepipeMessage> rawErrorMessages, QueueParameters parameters)
 {
     foreach (var rawErrorMessage in rawErrorMessages)
     {
         var error = serializer.BytesToMessage <Error>(Encoding.UTF8.GetBytes(rawErrorMessage.Body));
         RepublishError(error, parameters);
     }
 }
コード例 #19
0
ファイル: ErrorRetry.cs プロジェクト: rvsharma/EasyNetQ
 public void RetryErrors(IEnumerable <HosepipeMessage> rawErrorMessages, QueueParameters parameters)
 {
     foreach (var rawErrorMessage in rawErrorMessages)
     {
         var error = (Error)serializer.BytesToMessage(typeof(Error), errorMessageSerializer.Deserialize(rawErrorMessage.Body));
         RepublishError(error, parameters);
     }
 }
コード例 #20
0
ファイル: ErrorRetry.cs プロジェクト: ngbrown/EasyNetQ
 public void RetryErrors(IEnumerable<string> rawErrorMessages, QueueParameters parameters)
 {
     foreach (var rawErrorMessage in rawErrorMessages)
     {
         var error = serializer.BytesToMessage<Error>(Encoding.UTF8.GetBytes(rawErrorMessage));
         RepublishError(error, parameters);
     }
 }
コード例 #21
0
ファイル: Program.cs プロジェクト: zhangbo27/EasyNetQ
        private void Dump(QueueParameters parameters)
        {
            var count = 0;

            messageWriter.Write(WithEach(queueRetreival.GetMessagesFromQueue(parameters), () => count++), parameters);

            Console.WriteLine("{0} Messages from queue '{1}'\r\noutput to directory '{2}'",
                              count, parameters.QueueName, parameters.MessagesOutputDirectory);
        }
コード例 #22
0
ファイル: Program.cs プロジェクト: yonglehou/EasyNetQ
        public void Start(string[] args)
        {
            var arguments = argParser.Parse(args);

            var results = new StringBuilder();
            var succeeded = true;
            Func<string, Action> messsage = m => () =>
            {
                results.AppendLine(m);
                succeeded = false;
            };

            var parameters = new QueueParameters();
            arguments.WithKey("s", a => parameters.HostName = a.Value);
            arguments.WithKey("v", a => parameters.VHost = a.Value);
            arguments.WithKey("u", a => parameters.Username = a.Value);
            arguments.WithKey("p", a => parameters.Password = a.Value);
            arguments.WithKey("o", a => parameters.MessageFilePath = a.Value);
            arguments.WithKey("q", a => parameters.QueueName = a.Value);
            arguments.WithTypedKeyOptional<int>("n", a => parameters.NumberOfMessagesToRetrieve = int.Parse(a.Value))
                .FailWith(messsage("Invalid number of messages to retrieve"));
            arguments.WithTypedKeyOptional<bool>("x", a => parameters.Purge = bool.Parse(a.Value))
                .FailWith(messsage("Invalid purge (x) parameter"));

            try
            {
                arguments.At(0, "dump", () => arguments.WithKey("q", a => 
                {
                    parameters.QueueName = a.Value;
                    Dump(parameters);
                }).FailWith(messsage("No Queue Name given")));

                arguments.At(0, "insert", () => Insert(parameters));

                arguments.At(0, "err", () => ErrorDump(parameters));

                arguments.At(0, "retry", () => Retry(parameters));

                arguments.At(0, "?", PrintUsage);

                // print usage if there are no arguments
                arguments.At(0, a => {}).FailWith(PrintUsage);
            }
            catch (EasyNetQHosepipeException easyNetQHosepipeException)
            {
                Console.WriteLine("Operation Failed:");    
                Console.WriteLine(easyNetQHosepipeException.Message);
            }

            if(!succeeded)
            {
                Console.WriteLine("Operation failed");
                Console.Write(results.ToString());
                Console.WriteLine();
                PrintUsage();
            }
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: zhangbo27/EasyNetQ
        private void Insert(QueueParameters parameters)
        {
            var count = 0;

            queueInsertion.PublishMessagesToQueue(
                WithEach(messageReader.ReadMessages(parameters), () => count++), parameters);

            Console.WriteLine("{0} Messages from directory '{1}'\r\ninserted into queue '{2}'",
                              count, parameters.MessagesOutputDirectory, parameters.QueueName);
        }
コード例 #24
0
ファイル: ErrorRetry.cs プロジェクト: rvsharma/EasyNetQ
 public void RepublishError(Error error, QueueParameters parameters)
 {
     using (var connection = HosepipeConnection.FromParameters(parameters))
         using (var model = connection.CreateModel())
         {
             var properties = model.CreateBasicProperties();
             error.BasicProperties.CopyTo(properties);
             var body = errorMessageSerializer.Deserialize(error.Message);
             model.BasicPublish("", error.Queue, true, properties, body);
         }
 }
コード例 #25
0
ファイル: Program.cs プロジェクト: tzaavi/EasyNetQ
        private void Retry(QueueParameters parameters)
        {
            var count = 0;

            errorRetry.RetryErrors(
                WithEach(
                    messageReader.ReadMessages(parameters, DefaultConsumerErrorStrategy.EasyNetQErrorQueue),
                    () => count++),
                parameters);

            Console.WriteLine("{0} Error messages from directory '{1}' republished",
                              count, parameters.MessageFilePath);
        }
コード例 #26
0
        private void Retry(QueueParameters parameters)
        {
            var count = 0;

            errorRetry.RetryErrors(
                WithEach(
                    messageReader.ReadMessages(parameters, conventions.ErrorQueueNamingConvention()),
                    () => count++),
                parameters);

            Console.WriteLine("{0} Error messages from directory '{1}' republished",
                              count, parameters.MessageFilePath);
        }
コード例 #27
0
        private void Retry(QueueParameters parameters)
        {
            var count     = 0;
            var queueName = parameters.QueueName ?? conventions.ErrorQueueNamingConvention(null);

            errorRetry.RetryErrors(
                WithEach(messageReader.ReadMessages(parameters, queueName), () => count++), parameters
                );

            Console.WriteLine(
                "{0} error messages from directory '{1}' were republished", count, parameters.MessagesOutputDirectory
                );
        }
コード例 #28
0
ファイル: Program.cs プロジェクト: zhangbo27/EasyNetQ
        public void Start(string[] args)
        {
            var arguments = argParser.Parse(args);

            var parameters = new QueueParameters();

            arguments.WithKey("s", a => parameters.HostName  = a.Value);
            arguments.WithKey("sp", a => parameters.HostPort = Convert.ToInt32(a.Value));
            arguments.WithKey("v", a => parameters.VHost     = a.Value);
            arguments.WithKey("u", a => parameters.Username  = a.Value);
            arguments.WithKey("p", a => parameters.Password  = a.Value);
            arguments.WithKey("o", a => parameters.MessagesOutputDirectory = a.Value);
            arguments.WithKey("q", a => parameters.QueueName = a.Value);
            arguments.WithTypedKeyOptional <int>("n", a => parameters.NumberOfMessagesToRetrieve = int.Parse(a.Value))
            .FailWith(messsage("Invalid number of messages to retrieve"));
            arguments.WithTypedKeyOptional <bool>("x", a => parameters.Purge = bool.Parse(a.Value))
            .FailWith(messsage("Invalid purge (x) parameter"));

            try
            {
                arguments.At(0, "dump", () => arguments.WithKey("q", a =>
                {
                    parameters.QueueName = a.Value;
                    Dump(parameters);
                }).FailWith(messsage("No Queue Name given")));

                arguments.At(0, "insert", () => Insert(parameters));

                arguments.At(0, "err", () => ErrorDump(parameters));

                arguments.At(0, "retry", () => Retry(parameters));

                arguments.At(0, "?", PrintUsage);

                // print usage if there are no arguments
                arguments.At(0, a => {}).FailWith(PrintUsage);
            }
            catch (EasyNetQHosepipeException easyNetQHosepipeException)
            {
                Console.WriteLine("Operation Failed:");
                Console.WriteLine(easyNetQHosepipeException.Message);
            }

            if (!succeeded)
            {
                Console.WriteLine("Operation failed");
                Console.Write(results.ToString());
                Console.WriteLine();
                PrintUsage();
            }
        }
コード例 #29
0
ファイル: MessageReader.cs プロジェクト: nslowes/EasyNetQ
        public IEnumerable<string> ReadMessages(QueueParameters parameters, string messageName)
        {
            if (!Directory.Exists(parameters.MessageFilePath))
            {
                Console.WriteLine("Directory '{0}' does not exist", parameters.MessageFilePath);
                yield break;
            }

            var pattern = (messageName ?? "*") + ".*.message.txt";

            foreach (var file in Directory.GetFiles(parameters.MessageFilePath, pattern))
            {
                yield return File.ReadAllText(file);
            }
        }
コード例 #30
0
ファイル: MessageReader.cs プロジェクト: stepaside/EasyNetQ
        public IEnumerable <string> ReadMessages(QueueParameters parameters, string messageName)
        {
            if (!Directory.Exists(parameters.MessageFilePath))
            {
                Console.WriteLine("Directory '{0}' does not exist", parameters.MessageFilePath);
                yield break;
            }

            var pattern = (messageName ?? "*") + ".*.message.txt";

            foreach (var file in Directory.GetFiles(parameters.MessageFilePath, pattern))
            {
                yield return(File.ReadAllText(file));
            }
        }
コード例 #31
0
        public void PublishMessagesToQueue(IEnumerable <HosepipeMessage> messages, QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParamters(parameters))
                using (var channel = connection.CreateModel())
                {
                    foreach (var message in messages)
                    {
                        var body = Encoding.UTF8.GetBytes(message.Body);

                        var properties = new BasicProperties();
                        message.Properties.CopyTo(properties);

                        channel.BasicPublish(message.Info.Exchange, message.Info.RoutingKey, properties, body);
                    }
                }
        }
コード例 #32
0
        public void PublishMessagesToQueue(IEnumerable<HosepipeMessage> messages, QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParamters(parameters))
            using (var channel = connection.CreateModel())
            {
                foreach (var message in messages)
                {
                    var body = Encoding.UTF8.GetBytes(message.Body);

                    var properties = new BasicProperties();
                    message.Properties.CopyTo(properties);

                    channel.BasicPublish(message.Info.Exchange, message.Info.RoutingKey, properties, body);
                }
            }                        
        }
コード例 #33
0
        public void PublishMessagesToQueue(IEnumerable <HosepipeMessage> messages, QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParameters(parameters))
                using (var channel = connection.CreateModel())
                {
                    foreach (var message in messages)
                    {
                        var body = errorMessageSerializer.Deserialize(message.Body);

                        var properties = channel.CreateBasicProperties();
                        message.Properties.CopyTo(properties);

                        channel.BasicPublish(message.Info.Exchange, message.Info.RoutingKey, true, properties, body);
                    }
                }
        }
コード例 #34
0
ファイル: ErrorRetry.cs プロジェクト: y2ket/EasyNetQ
        public void RetryErrors(IEnumerable <HosepipeMessage> rawErrorMessages, QueueParameters parameters)
        {
            using var connection = HosepipeConnection.FromParameters(parameters);
            using var model      = connection.CreateModel();

            model.ConfirmSelect();

            foreach (var rawErrorMessage in rawErrorMessages)
            {
                var error      = (Error)serializer.BytesToMessage(typeof(Error), errorMessageSerializer.Deserialize(rawErrorMessage.Body));
                var properties = model.CreateBasicProperties();
                error.BasicProperties.CopyTo(properties);
                var body = errorMessageSerializer.Deserialize(error.Message);
                model.BasicPublish("", error.Queue, true, properties, body);
                model.WaitForConfirmsOrDie();
            }
        }
コード例 #35
0
ファイル: QueueInsertion.cs プロジェクト: rvsharma/EasyNetQ
        public void PublishMessagesToQueue(IEnumerable <HosepipeMessage> messages, QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParameters(parameters))
                using (var channel = connection.CreateModel())
                {
                    foreach (var message in messages)
                    {
                        var body = errorMessageSerializer.Deserialize(message.Body);

                        var properties = channel.CreateBasicProperties();
                        message.Properties.CopyTo(properties);

                        var queueName = string.IsNullOrEmpty(parameters.QueueName)
                        ? message.Info.Queue
                        : parameters.QueueName;
                        channel.BasicPublish("", queueName, true, properties, body);
                    }
                }
        }
コード例 #36
0
 public static IConnection FromParamters(QueueParameters parameters)
 {
     var connectionFactory = new ConnectionFactory
     {
         HostName = parameters.HostName,
         VirtualHost = parameters.VHost,
         UserName = parameters.Username,
         Password = parameters.Password
     };
     try
     {
         return connectionFactory.CreateConnection();
     }
     catch (BrokerUnreachableException)
     {
         throw new EasyNetQHosepipeException(string.Format(
             "The broker at '{0}', VirtualHost '{1}', is unreachable. This message can also be caused " + 
             "by incorrect credentials.",
             parameters.HostName,
             parameters.VHost));
     }
 } 
コード例 #37
0
        public void RetryErrors(IEnumerable <HosepipeMessage> rawErrorMessages, QueueParameters parameters)
        {
            using var connection = HosepipeConnection.FromParameters(parameters);
            using var model      = connection.CreateModel();
            model.ConfirmSelect();

            var errors = rawErrorMessages
                         .Select(x => (Error)serializer.BytesToMessage(typeof(Error), errorMessageSerializer.Deserialize(x.Body)))
                         .ToArray();

            var tempExchangeName = DeclareTemporaryExchange(model);

            try
            {
                RouteMessagesToExchange(model, tempExchangeName, errors);
                PublishMessages(model, tempExchangeName, errors);
            }
            finally
            {
                model.ExchangeDelete(tempExchangeName);
            }
        }
コード例 #38
0
ファイル: FileMessageWriter.cs プロジェクト: ngbrown/EasyNetQ
 public void Write(IEnumerable<string> messages, QueueParameters parameters)
 {
     var count = 0;
     foreach (string message in messages)
     {
         var fileName = parameters.QueueName + "." + count.ToString() + ".message.txt";
         var path = Path.Combine(parameters.MessageFilePath, fileName);
         if(File.Exists(path))
         {
             Console.WriteLine("Overwriting existing messsage file: {0}", path);
         }
         try
         {
             File.WriteAllText(path, message);
         }
         catch (DirectoryNotFoundException)
         {
             throw new EasyNetQHosepipeException(
                 string.Format("Directory '{0}' does not exist", parameters.MessageFilePath));
         }
         count++;
     }
 }
コード例 #39
0
        public IEnumerable <HosepipeMessage> GetMessagesFromQueue(QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParameters(parameters))
                using (var channel = connection.CreateModel())
                {
                    try
                    {
                        channel.QueueDeclarePassive(parameters.QueueName);
                    }
                    catch (OperationInterruptedException exception)
                    {
                        Console.WriteLine(exception.Message);
                        yield break;
                    }

                    var count = 0;
                    while (count++ < parameters.NumberOfMessagesToRetrieve)
                    {
                        var basicGetResult = channel.BasicGet(parameters.QueueName, parameters.Purge);
                        if (basicGetResult == null)
                        {
                            break;                     // no more messages on the queue
                        }
                        var properties = new MessageProperties(basicGetResult.BasicProperties);
                        var info       = new MessageReceivedInfo(
                            "hosepipe",
                            basicGetResult.DeliveryTag,
                            basicGetResult.Redelivered,
                            basicGetResult.Exchange,
                            basicGetResult.RoutingKey,
                            parameters.QueueName
                            );

                        yield return(new HosepipeMessage(errorMessageSerializer.Serialize(basicGetResult.Body.ToArray()), properties, info));
                    }
                }
        }
コード例 #40
0
        public void Write(IEnumerable <string> messages, QueueParameters parameters)
        {
            var count = 0;

            foreach (string message in messages)
            {
                var fileName = SanitiseQueueName(parameters.QueueName) + "." + count.ToString() + ".message.txt";
                var path     = Path.Combine(parameters.MessageFilePath, fileName);
                if (File.Exists(path))
                {
                    Console.WriteLine("Overwriting existing messsage file: {0}", path);
                }
                try
                {
                    File.WriteAllText(path, message);
                }
                catch (DirectoryNotFoundException)
                {
                    throw new EasyNetQHosepipeException(
                              string.Format("Directory '{0}' does not exist", parameters.MessageFilePath));
                }
                count++;
            }
        }
コード例 #41
0
ファイル: MessageReader.cs プロジェクト: nslowes/EasyNetQ
 public IEnumerable<string> ReadMessages(QueueParameters parameters)
 {
     return ReadMessages(parameters, null);
 }
コード例 #42
0
 public IEnumerable<HosepipeMessage> ReadMessages(QueueParameters parameters)
 {
     return ReadMessages(parameters, null);
 }
コード例 #43
0
ファイル: MessageReader.cs プロジェクト: stepaside/EasyNetQ
 public IEnumerable <string> ReadMessages(QueueParameters parameters)
 {
     return(ReadMessages(parameters, null));
 }
コード例 #44
0
ファイル: Program.cs プロジェクト: richard-green/EasyNetQ
        private void Retry(QueueParameters parameters)
        {
            var count = 0;
            errorRetry.RetryErrors(
                WithEach(
                    messageReader.ReadMessages(parameters, conventions.ErrorQueueNamingConvention()),
                    () => count++),
                parameters);

            Console.WriteLine("{0} Error messages from directory '{1}' republished",
                count, parameters.MessageFilePath);
        }
コード例 #45
0
ファイル: Program.cs プロジェクト: richard-green/EasyNetQ
        private void Insert(QueueParameters parameters)
        {
            var count = 0;
            queueInsertion.PublishMessagesToQueue(
                WithEach(messageReader.ReadMessages(parameters), () => count++), parameters);

            Console.WriteLine("{0} Messages from directory '{1}'\r\ninserted into queue '{2}'",
                count, parameters.MessageFilePath, parameters.QueueName);
        }
コード例 #46
0
ファイル: Program.cs プロジェクト: richard-green/EasyNetQ
 private void ErrorDump(QueueParameters parameters)
 {
     parameters.QueueName = conventions.ErrorQueueNamingConvention();
     Dump(parameters);
 }
コード例 #47
0
ファイル: Program.cs プロジェクト: richard-green/EasyNetQ
        private void Dump(QueueParameters parameters)
        {
            var count = 0;
            messageWriter.Write(WithEach(queueRetreival.GetMessagesFromQueue(parameters), () => count++), parameters);

            Console.WriteLine("{0} Messages from queue '{1}'\r\noutput to directory '{2}'",
                count, parameters.QueueName, parameters.MessageFilePath);
        }
コード例 #48
0
ファイル: Program.cs プロジェクト: nslowes/EasyNetQ
        private void Retry(QueueParameters parameters)
        {
            var count = 0;
            errorRetry.RetryErrors(
                WithEach(
                    messageReader.ReadMessages(parameters, DefaultConsumerErrorStrategy.EasyNetQErrorQueue),
                    () => count++),
                parameters);

            Console.WriteLine("{0} Error messages from directory '{1}' republished",
                count, parameters.MessageFilePath);
        }
コード例 #49
0
ファイル: Program.cs プロジェクト: nslowes/EasyNetQ
 private void ErrorDump(QueueParameters parameters)
 {
     parameters.QueueName = DefaultConsumerErrorStrategy.EasyNetQErrorQueue;
     Dump(parameters);
 }
コード例 #50
0
 private void ErrorDump(QueueParameters parameters)
 {
     parameters.QueueName = conventions.ErrorQueueNamingConvention();
     Dump(parameters);
 }
コード例 #51
0
ファイル: MessageReader.cs プロジェクト: xw-fighting/EasyNetQ
 public IEnumerable <HosepipeMessage> ReadMessages(QueueParameters parameters)
 {
     return(ReadMessages(parameters, null));
 }