kafka - HowardWhile/2022_note GitHub Wiki

kafka

windows 上使用kafka

https://ithelp.ithome.com.tw/articles/10217344

  • Address
10.176.44.171:9092
10.176.44.172:9092
10.176.44.173:9092
  • topic

gl-cnc-vibration

啟動服務器

cd ~/scoop/apps/kafka/current/bin/windows/
./zookeeper-server-start.bat ../../config/zookeeper.properties
cd ~/scoop/apps/kafka/current/bin/windows/
./kafka-server-start.bat ../../config/server.properties

創建主題(Topic)

cd ~/scoop/apps/kafka/current/bin/windows/
./kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic gl-cnc-vibration 

刪除主題

cd ~/scoop/apps/kafka/current/bin/windows/
./kafka-topics.bat --bootstrap-server localhost:9092 --delete --topic gl-cnc-vibration 

顯示所有主題

cd ~/scoop/apps/kafka/current/bin/windows/
./kafka-topics.bat --list --bootstrap-server localhost:9092
./kafka-topics.bat --list --bootstrap-server 10.176.44.171:9092

發送訊息

cd ~/scoop/apps/kafka/current/bin/windows/
./kafka-console-producer.bat --broker-list localhost:9092 --topic gl-cnc-vibration

接收訊息

cd ~/scoop/apps/kafka/current/bin/windows/
./kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic gl-cnc-vibration --from-beginning
./kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic gl-cnc-vibration
./kafka-console-consumer.bat --bootstrap-server 10.176.44.171:9092 --topic gl-cnc-vibration

C# kafka

https://github.com/confluentinc/confluent-kafka-dotnet/

image-20220819165958322

var conf = new ProducerConfig { BootstrapServers = this.tbox_address.Text };
using (var p = new ProducerBuilder<Null, string>(conf).Build())
{
	p.Produce(this.tbox_topic.Text, new Message<Null, string> { Value = this.tbox_message.Text });
	p.Flush(TimeSpan.FromSeconds(10));
}

Home