コード例 #1
0
        private static async Task MainAsync(string[] args)
        {
            //            var queuePrefix = args[0];
//            var queueCount = int.Parse(args[1]);

            var resourceGroup  = "group";
            var queuePrefix    = "rb";
            var queueCount     = 10;
            var exchange       = "input-seq";
            var rmqHost        = "localhost";
            var zooKeeperHosts = "zk1:2181,zk2:2181,zk3:2181";
            var rmqNodes       = "rabbit@rabbitmq1,rabbit@rabbitmq2,rabbit@rabbitmq3";

            var rabbitConn = new RabbitConnection()
            {
                Host           = rmqHost,
                Password       = "******",
                ManagementPort = 15672,
                Port           = 5672,
                Username       = "******",
                VirtualHost    = "/"
            };
            var queueManager = new QueueManager();
            await queueManager.InitializeAsync(rabbitConn, zooKeeperHosts, rmqNodes);

            await queueManager.MeetDesiredStateAsync(resourceGroup, queuePrefix, queueCount, exchange);
        }
コード例 #2
0
        public async Task InitializeAsync(RabbitConnection rabbitConnection, string zooKeeperHosts, string rabbitMQNodes)
        {
            var sw = new Stopwatch();

            sw.Start();
            this.httpClient             = new HttpClient();
            this.httpClient.BaseAddress = new Uri($"http://{rabbitConnection.Host}:{rabbitConnection.ManagementPort}/api/");
            var byteArray = Encoding.ASCII.GetBytes($"{rabbitConnection.Username}:{rabbitConnection.Password}");

            this.httpClient.DefaultRequestHeaders.Authorization
                = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

            this.nodes    = rabbitMQNodes.Split(",").ToList();
            this.zkHelper = new ZkHelper();
            await this.zkHelper.InitializeAsync(zooKeeperHosts, "/rebalanser", TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30));
        }