-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
A19 - Kafka/présentationKAFKA/2- ATLIER #1 KAFKA-WINDOWS.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
*********************************** | ||
**************ATLIER KAFKA********* | ||
*********************************** | ||
*****1- Démarrez ZOOKEEPER | ||
C:\HADOOP\kafka_2.12-3.5.0\bin\windows\zookeeper-server-start.bat C:\HADOOP\kafka_2.12-3.5.0\config\zookeeper.properties | ||
|
||
*****2- Démarrez le serveur KAFKA | ||
C:\HADOOP\kafka_2.12-3.5.0\bin\windows\kafka-server-start.bat C:\HADOOP\kafka_2.12-3.5.0\config\server.properties | ||
|
||
*****3- Création d'un premier topic (ouvrir CMD dans windows) | ||
kafka-topics --bootstrap-server localhost:9092 --topic justine --create --partitions 1 --replication-factor 1 | ||
|
||
*****4- Création de plusieurs topics (ouvrir CMD dans windows) | ||
kafka-topics --bootstrap-server localhost:9092 --topic myfirst --create --partitions 1 --replication-factor 1 | ||
kafka-topics --bootstrap-server localhost:9092 --topic mysecond --create --partitions 1 --replication-factor 1 | ||
kafka-topics --bootstrap-server localhost:9092 --topic mythird --create --partitions 1 --replication-factor 1 | ||
|
||
*****5- lister les topics | ||
kafka-topics --bootstrap-server localhost:9092 -list | ||
|
||
*****6- décrire un topic spécéfique | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic justine | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic myfirst | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic mysecond | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic mythird | ||
|
||
*****7- Création d'un 4ème topic avec un facteur de répartition =3 (ouvrir CMD dans windows) | ||
kafka-topics --bootstrap-server localhost:9092 --topic myfourth --create --partitions 3 --replication-factor 1 | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic myfourth | ||
|
||
|
||
*****8- Création d'un 5ème topic avec un facteur de réplication =3 (ouvrir CMD dans windows) | ||
kafka-topics --bootstrap-server localhost:9092 --topic myfifth --create --partitions 1 --replication-factor 3 | ||
|
||
|
||
***Toutes les commandes | ||
C:\HADOOP\kafka_2.12-3.5.0\bin\windows\zookeeper-server-start.bat C:\HADOOP\kafka_2.12-3.5.0\config\zookeeper.properties | ||
C:\HADOOP\kafka_2.12-3.5.0\bin\windows\kafka-server-start.bat C:\HADOOP\kafka_2.12-3.5.0\config\server.properties | ||
kafka-topics --bootstrap-server localhost:9092 --topic justine --create --partitions 1 --replication-factor 1 | ||
kafka-topics --bootstrap-server localhost:9092 --topic myfirst --create --partitions 1 --replication-factor 1 | ||
kafka-topics --bootstrap-server localhost:9092 --topic mysecond --create --partitions 1 --replication-factor 1 | ||
kafka-topics --bootstrap-server localhost:9092 --topic mythird --create --partitions 1 --replication-factor 1 | ||
kafka-topics --bootstrap-server localhost:9092 -list | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic justine | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic myfirst | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic mysecond | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic mythird |
47 changes: 47 additions & 0 deletions
47
A19 - Kafka/présentationKAFKA/3- ATLIER #1 KAFKA-LINUX2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
*********************************** | ||
**************ATLIER KAFKA********* | ||
*********************************** | ||
*****1- Démarrez ZOOKEEPER | ||
bin/zookeeper-server-start.sh config/zookeeper.properties | ||
|
||
*****2- Démarrez le serveur KAFKA | ||
bin/kafka-server-start.sh config/server.properties | ||
|
||
*****3- Création d'un premier topic (ouvrir CMD dans windows) | ||
./kafka-topics.sh --bootstrap-server localhost:9092 --topic justine --create --partitions 1 --replication-factor 1 | ||
|
||
*****4- Création de plusieurs topics (ouvrir CMD dans windows) | ||
./kafka-topics.sh --bootstrap-server localhost:9092 --topic myfirst --create --partitions 1 --replication-factor 1 | ||
./kafka-topics.sh --bootstrap-server localhost:9092 --topic mysecond --create --partitions 1 --replication-factor 1 | ||
./kafka-topics.sh --bootstrap-server localhost:9092 --topic mythird --create --partitions 1 --replication-factor 1 | ||
|
||
*****5- lister les topics | ||
./kafka-topics.sh --bootstrap-server localhost:9092 -list | ||
|
||
*****6- décrire un topic spécéfique | ||
./kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic justine | ||
./kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic myfirst | ||
./kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic mysecond | ||
./kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic mythird | ||
|
||
*****7- Création d'un 4ème topic avec un facteur de répartition =3 (ouvrir CMD dans windows) | ||
./kafka-topics.sh --bootstrap-server localhost:9092 --topic myfourth --create --partitions 3 --replication-factor 1 | ||
./kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic myfourth | ||
|
||
|
||
*****8- Création d'un 5ème topic avec un facteur de réplication =3 (ouvrir CMD dans windows) | ||
kafka-topics --bootstrap-server localhost:9092 --topic myfifth --create --partitions 1 --replication-factor 3 | ||
|
||
|
||
***Toutes les commandes | ||
C:\HADOOP\kafka_2.12-3.5.0\bin\windows\zookeeper-server-start.bat C:\HADOOP\kafka_2.12-3.5.0\config\zookeeper.properties | ||
C:\HADOOP\kafka_2.12-3.5.0\bin\windows\kafka-server-start.bat C:\HADOOP\kafka_2.12-3.5.0\config\server.properties | ||
kafka-topics --bootstrap-server localhost:9092 --topic justine --create --partitions 1 --replication-factor 1 | ||
kafka-topics --bootstrap-server localhost:9092 --topic myfirst --create --partitions 1 --replication-factor 1 | ||
kafka-topics --bootstrap-server localhost:9092 --topic mysecond --create --partitions 1 --replication-factor 1 | ||
kafka-topics --bootstrap-server localhost:9092 --topic mythird --create --partitions 1 --replication-factor 1 | ||
kafka-topics --bootstrap-server localhost:9092 -list | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic justine | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic myfirst | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic mysecond | ||
kafka-topics --bootstrap-server localhost:9092 --describe --topic mythird |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Importing necessary libraries | ||
from kafka import KafkaConsumer | ||
import json | ||
|
||
# Configuration for Kafka consumer | ||
consumer_conf = { | ||
# Set the bootstrap servers based on your Kafka cluster and host names | ||
# For a single node (localhost) setup, use 'localhost:9092' | ||
'bootstrap_servers': ['localhost:9092'], | ||
'group_id': 'my_group', | ||
'auto_offset_reset': 'latest', | ||
'value_deserializer': lambda v: json.loads(v.decode('utf-8')) | ||
} | ||
|
||
# Creating Kafka consumer instance | ||
consumer = KafkaConsumer('my-topic-test', **consumer_conf) | ||
|
||
# Consuming messages from Kafka | ||
for message in consumer: | ||
print(f"Received message: {message.value}") | ||
|
||
# Closing the consumer | ||
consumer.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Importing necessary libraries | ||
import json | ||
from kafka import KafkaProducer | ||
import time | ||
|
||
# Configuration for Kafka producer | ||
producer_conf = { | ||
# Set the bootstrap servers based on your Kafka cluster and host names | ||
# For example, 'your-host-name:9092' | ||
'bootstrap_servers': ['localhost:9092'], | ||
'value_serializer': lambda v: json.dumps(v).encode('utf-8') | ||
} | ||
|
||
# Creating Kafka producer instance | ||
producer = KafkaProducer(**producer_conf) | ||
|
||
# Define the topic name | ||
topic_name = 'my-topic-test' | ||
|
||
# Sending messages to Kafka | ||
for i in range(100): | ||
message = {'this is message #': i} | ||
|
||
producer.send(topic_name, value=message) | ||
print(f'Message sent: {message}') | ||
time.sleep(1) | ||
|
||
# Flush and close the producer | ||
producer.flush() | ||
producer.close() |