Skip to content

Commit

Permalink
golang
Browse files Browse the repository at this point in the history
  • Loading branch information
刘鹏杰 authored and 刘鹏杰 committed Mar 27, 2018
1 parent b3023f9 commit 749fead
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
Binary file modified .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions 20golang_kafka/1.kafka介绍.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ kafka链接zookeeper
$ cd bin
$ kafka-console-consumer.sh --topic nginx_log --zookeeper 127.0.0.1 2181
(Windows 执行kafka-console-consumer.bat --topic nginx_log --zookeeper 127.0.0.1 2181)


查看topic的详细信息
bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --topic nginx_log --describe
kafka消费者客户端命令
bin/kafka-console-consumer.sh --zookeeper 127.0.0.1:2181 --topic nginx_log --from-beginning
42 changes: 26 additions & 16 deletions 20golang_kafka/3.kafka消费.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ func main() {
return
}
defer pc.AsyncClose()
wg.Add(1)
go func(pc sarama.PartitionConsumer) {
wg.Add(1)
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()
}
wg.Done()

}(pc)
}
//time.Sleep(time.Hour)
Expand All @@ -51,6 +52,7 @@ func main() {




创建生产者producer
package main

Expand Down Expand Up @@ -101,19 +103,27 @@ consumer.go producer.go
启动kafka
启动kafka链接zookeeper


开启消费者
$ go run consumer.go

开启生产者
$ go run producer.go
pid:0 offset:1678
pid:0 offset:1679
pid:0 offset:1680
pid:0 offset:1681
pid:0 offset:1682
pid:0 offset:1683
pid:0 offset:1684
pid:0 offset:1685
pid:0 offset:1686


开启消费者//消费代码有问题待解决
$ go run consumer.go
[0]
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
14 changes: 14 additions & 0 deletions 21golang_ElasticSearch/1.ElasticSearch介绍.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ElasticSearch介绍与使用

https://www.elastic.co/cn/ Elasticsearch官网(下载ElasticSearch)

http://www.jianshu.com/p/05cff717563c
ElasticSearch一款非常优秀的分布式搜索程序

ElasticSearch安装
1) 下载ElasticSearch下载地github.com/elastic/elasticsearch
2) 修改config/elasticsearch.ymal配置
network.host: 本地ip
node.name:node-1
如果电脑配置不够修改config/ jvm.options -Xms512m -Xmx512m
3) 启动ElasticSearch, ./bin/elasticsearch.bat

0 comments on commit 749fead

Please sign in to comment.