kafka介紹:
1、安裝工具brew install kafka 會自動安裝依賴zookeeper
2、安裝配置檔案位置 /usr/local/etc/kafka|zookeeper
3、啟動 zookeeper
cd /usr/local/cellar/kafka/0.10.0.1
./bin/zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties &
4、啟動kafka服務
./bin/kafka-server-start /usr/local/etc/kafka/server.properties &
5、建立topic
./bin/kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test1
6、檢視建立的topic
./bin/kafka-topics --list --zookeeper localhost:2181
7、生產資料
./bin/kafka-console-producer --broker-list localhost:9092 --topic test1
8、消費資料
./bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test1--from-beginning
下面給出乙個python**演示demo,首先保證你已經安裝python-kafak。
建立生產者:procucer.py
from kafka import kafkaproducer
import time
import logging
import sys
logging.basicconfig(
stream=sys.stdout,
level=logging.info,
format='%(asctime)s.%(msecs)d %(filename)s[line:%(lineno)d] %(levelname)s: %(message)s',
datefmt='%y/%m/%d %h:%m:%s'
)log = logging.getlogger('kafka demo')
def list_file():
while true:
log.info("===>>>running")
time.sleep(2)
producer.send('world',key=b'foo', value=b'bar')
producer.flush()
if __name__ == '__main__':
producer = kafkaproducer(bootstrap_servers='localhost:9092')
list_file()
producer.close()
建立消費者:consumer.py
# -*- encoding=utf-8 -*-
from kafka import kafkaconsumer
import logging
import sys
logging.basicconfig(
stream=sys.stdout,
level=logging.info,
format='%(asctime)s.%(msecs)d %(filename)s[line:%(lineno)d] %(levelname)s: %(message)s',
datefmt='%y/%m/%d %h:%m:%s'
)log = logging.getlogger('kafka demo')
if __name__ == '__main__':
consumer = kafkaconsumer('world', group_id='consumer-20171017', bootstrap_servers=['localhost:9092'])
for msg in consumer:
recv = "%s:%d:%d: key=%s value=%s" % (msg.topic, msg.partition, msg.offset, msg.key, msg.value)
log.info(recv)
然後,分別執行這2個檔案就可以模擬了。
完整源**:
參考:1.
2.
mac下滲透測試環境搭建
比較懶,想起什麼就往上面新增什麼。burpsuite 感覺這個是最方便的了,其他的破解後還要弄圖示什麼的,這個是直接安裝 然後是jdk,我現在用的是jdk16,但是很多時候都要用到jdk1.8這種低版本的,所以找了一下安裝兩個版本的jdk隨時切換 還有就是clashx,挺好用的,或者是shadows...
Linux下搭建kafka環境
apache官網 tar xzf kafka 2.10 0.8.2.2.tgz cd kafka 2.10 0.8.2.2 啟動zk有兩種方式,第一種是使用kafka自己帶的乙個zk。bin zookeeper server start.sh config zookeeper.properties ...
Linux下搭建kafka環境
apache官網 tar xzf kafka 2.10 0.8.2.2.tgz cd kafka 2.10 0.8.2.2 3.啟動服務 3.1 啟動zookeeper 啟動zk有兩種方式,第一種是使用kafka自己帶的乙個zk。bin zookeeper server start.sh confi...