Пример #1
0
        static void Main2(string[] args)
        {
            var environment = new List<KeyValuePair<string, string>>();

            environment.Add(new KeyValuePair<string, string>("MongoServer", "localhost"));
            environment.Add(new KeyValuePair<string, string>("MongoPort", "27017"));
            environment.Add(new KeyValuePair<string, string>("MongoRepositorySvcConfig", "ServiceConfig"));
            environment.Add(new KeyValuePair<string, string>("RabbitMQServer", "localhost"));
            environment.Add(new KeyValuePair<string, string>("RabbitMQPort", "5672"));
            environment.Add(new KeyValuePair<string, string>("RabbitMQVHost", "/Dev"));

            var mongoEnv = environment.Where(kvp => kvp.Key.StartsWith("Mongo"));
            var rabbitEnv = environment.Where(kvp => kvp.Key.StartsWith("Rabbit"));

            using (var mbc = new MessageBrokerConnection(rabbitEnv))
            {
                using (var cl = new CommandConsumer(mbc.Connection))
                {
                    cl.RegisterCommandHandler<ReloadFiles>((props, cmd) =>
                    {
                        //Console.WriteLine("{0:G}: {1}", cmd.Created.ToLocalTime(), props.Type);
                        return new ReloadFilesAck(cmd);
                    });

                    var loops = 10000;
                    var successCounter = 0;
                    var failCounter = 0;
                    var cumulativeTime = 0L;
                    var sw = new Stopwatch();

                    var cmdExchange = Constants.CmdExchangeSettings;
                    using (var cs = new CommandProducer(mbc.Connection))
                    {
                        for (int i = 0; i < loops; i++)
                        {
                            sw.Reset();
                            sw.Start();

                            var reply = cs.Publish(new ReloadFiles(), cl.PublicationAddress, TimeSpan.FromMilliseconds(20d));
                            sw.Stop();

                            if (reply != null)
                            {
                                ++successCounter;
                                cumulativeTime += sw.ElapsedMilliseconds;
                            }
                            else
                                ++failCounter;
                        }
                    }

                    Console.WriteLine("{0} Command(s) Sent, {1} Successes, {2} Fails, {3}ms elapsed", loops, successCounter, failCounter, cumulativeTime);
                    Console.WriteLine("Press Enter to continue");
                    Console.ReadLine();
                }
            }
        }