예제 #1
0
        public Producer(string zkconfig, string topic)
        {
            zk = new ZKClient(zkconfig);
            zk.push(topic);
            broker = zk.findBroker();
            if (broker != null)
            {
                string[] uri = broker.brokerUri.Split(':');
                host = uri[0];
                port = Convert.ToInt32(uri[1]);
            }

            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                socket.Connect(host, port);
            }
            catch (SocketException e)
            {
                Debug.Write(e.ToString());
            }

        }
예제 #2
0
        public void push(string topic)
        {
            lock (syncRoot)
            {
                brokers.Clear();
                this.getChildren("/meta/brokers/topics/" + topic).ForEach((s) =>
                {
                    var n = Convert.ToInt32(this.getData("/meta/brokers/topics/" + topic + "/" + s));// partition number 
                    var id = Convert.ToInt32(s.Split('-')[0]);
                    var broker_full_uri = this.getData("/meta/brokers/ids/" + id + "/master");
                    var broker_uri = broker_full_uri.Replace("meta://", "");
                    Broker broker = new Broker(id, broker_uri);
                    for (int index = 0; index < n; index++)
                    {
                        broker.partitions.Add(new Partition(id,index));
                    }
                    brokers.Add(id, broker);
                    Debug.WriteLine("========= brokers list ==========");
                    Debug.WriteLine("broker: " + id + " -> " + broker_uri);
                });

            }

        }