Пример #1
0
        static void Main(string[] args)
        {
            var timeout = TimeSpan.FromSeconds(1d);

            var configClient = new SvcComponentConfig.SvcComponentConfigClient();

            // Get the list of environments, and make sure Dev is in the list
            var environments = configClient.GetEnvironments();
            var env = environments.Single(s => s == "Dev");

            // Get the Dev environment configuration
            var environment = configClient.GetEnvironmentConfig(env);
            var mongoEnv = environment.Where(kvp => kvp.Key.StartsWith("Mongo"));
            var rabbitEnv = environment.Where(kvp => kvp.Key.StartsWith("Rabbit"));

            var provider = new ServiceHostProvider(mongoEnv);

            using (var mbc = new MessageBrokerConnection(rabbitEnv))
            using (var cs = new CommandProducer(mbc.Connection))
            using (var wp = new WorkProducer(mbc.Connection))
            {
                var exit = false;
                Console.WriteLine("Press F to reload Files");
                Console.WriteLine("Press C to reload Configuration");
                Console.WriteLine("Press T to sTart component");
                Console.WriteLine("Press P to stoP component");
                Console.WriteLine("Press A to Activate component");
                Console.WriteLine("Press D to Deactivate component");
                Console.WriteLine("Press S to pauSe component");
                Console.WriteLine("Press N to coNtinue component");
                Console.WriteLine("Press W to create work");
                Console.WriteLine("Press x to exit");

                do
                {
                    var cki = Console.ReadKey(true);
                    string keyChar = new string(cki.KeyChar, 1);

                    if (string.Compare("x", keyChar, true, CultureInfo.InvariantCulture) == 0)
                        exit = true;

                    else if (string.Compare("w", keyChar, true, CultureInfo.InvariantCulture) == 0)
                        wp.Publish(new SampleWorkItem(), "SampleWorkQueue");

                    else
                    {
                        var sh = GetServiceHost(provider);
                        var pa = PublicationAddress.Parse(sh.CommandMessageQueue);

                        if (string.Compare("f", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new ReloadFiles() { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("c", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new ReloadConfiguration() { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("t", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new StartComponent(sh.Components.First().Id) { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("p", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new StopComponent(sh.Components.First().Id) { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("a", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new ActivateComponent(sh.Components.First().Id) { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("d", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new DeactivateComponent(sh.Components.First().Id) { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("s", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new PauseComponent(sh.Components.First().Id) { CorrelationId = Guid.NewGuid() }, pa, timeout);

                        else if (string.Compare("n", keyChar, true, CultureInfo.InvariantCulture) == 0)
                            cs.Publish(new ContinueComponent(sh.Components.First().Id) { CorrelationId = Guid.NewGuid() }, pa, timeout);
                    }
                }
                while (!exit);
            }
        }
Пример #2
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();
                }
            }
        }