public Controller(Options options) : base(options) { }
private static int Main(string[] args) { Options options = new Options(); CommandLineParser parser = new CommandLineParser(options); parser.Parse(); if (parser.HasErrors) { Console.WriteLine(parser.UsageInfo.GetErrorsAsString(78)); return -1; } if (options.Help) { Console.WriteLine(parser.UsageInfo.GetOptionsAsString(78)); return 0; } bool singleProcess = (!options.Setup && !options.Control && !options.Publish && !options.Subscribe); if (singleProcess) { options.Setup = options.Control = options.Publish = true; options.Subscribe = true; } string exchange = "amq.direct"; switch (options.Mode) { case "shared": options.SubQuota = (options.Pubs*options.Count)/options.Subs; break; case "fanout": options.SubQuota = (options.Pubs*options.Count); exchange = "amq.fanout"; break; case "topic": options.SubQuota = (options.Pubs*options.Count); exchange = "amq.topic"; break; } if (options.Setup) { SetupTest setup = new SetupTest(options); setup.Start(); // Set up queues } Thread contT = null; if ( options.Control) { Controller c = new Controller(options); contT = new Thread(c.Start); contT.Start(); } Thread[] publishers = null; Thread[] subscribers = null; // Start pubs/subs for each queue/topic. for (int i = 0; i < options.Queues; ++i) { string key = "perftest" + i; // Queue or topic name. if (options.Publish) { int n = singleProcess ? options.Pubs : 1; publishers = new Thread[n]; for (int j = 0; j < n; ++j) { PublishThread pt = new PublishThread(options, key, exchange); publishers[i] = new Thread(pt.Start); publishers[i].Start(); } } if ( options.Subscribe) { int n = singleProcess ? options.Subs : 1; subscribers = new Thread[n]; for (int j = 0; j < n; ++j) { SubscribeThread st; if (options.Mode.Equals("shared")) st = new SubscribeThread(options, key); else st = new SubscribeThread(options, key, exchange); subscribers[i] = new Thread(st.Start); subscribers[i].Start(); } } } if (options.Control) { contT.Join(); } // Wait for started threads. if (options.Publish) { foreach (Thread t in publishers) { t.Join(); } } if (options.Subscribe) { foreach (Thread t in subscribers) { t.Join(); } } return 0; }
public PublishThread(Options options, string key, string exchange) : base(options) { _key = key; _exchange = exchange; }
public SubscribeThread(Options options, string key) : base(options) { _queue = key; }
public SubscribeThread(Options options, string key, string exchange) : base(options) { _queue = "perftest" + (new UUID(10, 10)); Session.QueueDeclare(_queue, null, null, Option.EXCLUSIVE, Option.AUTO_DELETE, Options.Durable ? Option.DURABLE : Option.NONE); Session.ExchangeBind(_queue, exchange, key); }
public SetupTest(Options options) : base(options) { }
protected PerfTestClient(Options options) { _options = options; _connection = new Client(); _connection.Connect(options.Broker, options.Port, "test", "guest", "guest"); _session = _connection.CreateSession(50000); }