<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                創建消費者:consumer.go ~~~ package main import ( "fmt" "strings" "sync" "github.com/Shopify/sarama" ) var ( wg sync.WaitGroup ) func main() { //創建消費者 consumer, err := sarama.NewConsumer(strings.Split("192.168.1.125:9092", ","), nil) if err != nil { fmt.Println("Failed to start consumer: %s", err) return } //設置分區 partitionList, err := consumer.Partitions("nginx_log") if err != nil { fmt.Println("Failed to get the list of partitions: ", err) return } fmt.Println(partitionList) //循環分區 for partition := range partitionList { pc, err := consumer.ConsumePartition("nginx_log", int32(partition), sarama.OffsetNewest) if err != nil { fmt.Printf("Failed to start consumer for partition %d: %s\n", partition, err) return } defer pc.AsyncClose() wg.Add(1) go func(pc sarama.PartitionConsumer) { defer wg.Done() for msg := range pc.Messages() { fmt.Printf("Partition:%d, Offset:%d, Key:%s, Value:%s", msg.Partition, msg.Offset, string(msg.Key), string(msg.Value)) fmt.Println() } }(pc) } //time.Sleep(time.Hour) wg.Wait() consumer.Close() } ~~~ 創建生產者:producer.go ~~~ package main import ( "fmt" "time" "github.com/Shopify/sarama" ) func main() { config := sarama.NewConfig() config.Producer.RequiredAcks = sarama.WaitForAll config.Producer.Partitioner = sarama.NewRandomPartitioner config.Producer.Return.Successes = true client, err := sarama.NewSyncProducer([]string{"192.168.1.125:9092"}, config) if err != nil { fmt.Println("producer close, err:", err) return } defer client.Close() for { msg := &sarama.ProducerMessage{} msg.Topic = "nginx_log" msg.Value = sarama.StringEncoder("this is a good test, my message is good") pid, offset, err := client.SendMessage(msg) if err != nil { fmt.Println("send message failed,", err) return } fmt.Printf("pid:%v offset:%v\n", pid, offset) time.Sleep(10 * time.Millisecond) } } ~~~ 準備工作: ~~~ ls consumer.go producer.go ~~~ ~~~ 啟動zookeeper 啟動kafka 啟動kafka鏈接zookeeper ~~~ 開啟消費者: ~~~ go run consumer.go ~~~ 開啟生產者: ~~~ go run producer.go pid:0 offset:1930 pid:0 offset:1931 pid:0 offset:1932 pid:0 offset:1933 pid:0 offset:1934 pid:0 offset:1935 pid:0 offset:1936 pid:0 offset:1937 pid:0 offset:1938 ~~~ 消費者顯示: ~~~ Partition:0, Offset:1930, Key:, Value:this is a good test, my message is good Partition:0, Offset:1931, Key:, Value:this is a good test, my message is good Partition:0, Offset:1932, Key:, Value:this is a good test, my message is good Partition:0, Offset:1933, Key:, Value:this is a good test, my message is good Partition:0, Offset:1934, Key:, Value:this is a good test, my message is good Partition:0, Offset:1935, Key:, Value:this is a good test, my message is good ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看