kafka 安装内存会报不够
https://stackoverflow.com/questions/9350437/incompatible-initial-and-maximum-heap-sizes-specified
Picked up _JAVA_OPTIONS: -Xmx1024M
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000b5a00000, 1073741824, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 1073741824 bytes for committing reserved memory.
需要调整jvm
export _JAVA_OPTIONS=-Xmx1024M
export _JAVA_OPTIONS=-Xms512M
bin/kafka-server-start.sh config/server.properties
Picked up _JAVA_OPTIONS: -Xms512M
创建topic
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic a2
Created topic "a2".
查看topic
bin/kafka-topics.sh --list --zookeeper localhost:2181
发送消息到指定的topic
bin
/kafka-console-producer
.sh --broker-list localhost:9092 --topic
test
WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 1 : {test=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
如果发现是没有leader的提示错误,需要修改配置文件
"github.com/Shopify/sarama" 不支持group,不支持rebanlance。
1 func kafka_exampe() { 2 3 consumer, err := sarama.NewConsumer([]string{"192.168.199.133:9092"}, nil) 4 if err != nil { 5 panic(err) 6 } 7 8 defer func() { 9 if err := consumer.Close(); err != nil { 10 log.Fatalln(err) 11 } 12 }() 13 14 partitionConsumer, err := consumer.ConsumePartition("test", 0, sarama.OffsetNewest) 15 if err != nil { 16 panic(err) 17 } 18 19 defer func() { 20 if err := partitionConsumer.Close(); err != nil { 21 log.Fatalln(err) 22 } 23 }() 24 25 // Trap SIGINT to trigger a shutdown. 26 signals := make(chan os.Signal, 1) 27 signal.Notify(signals, os.Interrupt) 28 29 consumed := 0 30 ConsumerLoop: 31 for { 32 select { 33 case msg := <-partitionConsumer.Messages(): 34 log.Printf("Consumed message offset %d ", msg.Offset) 35 log.Printf(string(msg.Value)) 36 consumed++ 37 case <-signals: 38 break ConsumerLoop 39 } 40 } 41 42 log.Printf("Consumed: %d ", consumed) 43 }