This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from opt-nc/20-fournir-quickstartmd
20 fournir quickstartmd
- Loading branch information
Showing
8 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,55 @@ | ||
# __QuickStart__ | ||
|
||
## ℹ️ Prérequis | ||
|
||
Les éléments suivant doivent-être installés : | ||
|
||
* <a href="https://docs.docker.com/engine/install/" target="_blank"> Docker </a> | ||
* <a href="https://www.jbang.dev/documentation/guide/latest/installation.html" target="_blank"> JBang </a> | ||
* <a href="https://camel.apache.org/manual/camel-jbang.html" target="_blank"> Camel-JBang </a> | ||
|
||
Les ports suivant doivent-être libres pour que les conteneurs Docker puissent fonctionner : | ||
|
||
* 8080 - opt-temps-attente-agences-api | ||
* 8888 - kowl | ||
* 9092 / 9093 - kafka | ||
* 2181 - zookeeper | ||
|
||
Ajouter danse le fichier host la ligne suivante : | ||
```bash | ||
127.0.0.1 kafka | ||
``` | ||
|
||
## Description des livrables | ||
|
||
Le répertoire _scripts_ contient : | ||
|
||
* 2 fichiers routes en xml | ||
|
||
* _route-kafka.xml_ : récupère les données de l'api temps-d'attente et les routes vers Kafka (Producer) | ||
* _route-kafka-jsont.xml_ : récupère le données depuis le topic Kafka et les stocke dans un fichier JSON (Consumer) dans le répertoire _files_ | ||
* 1 fichier yaml _temps_attente.yml_ : exécutable avec Docker Compose pour le lancement des différents conteneurs nécessaires (opt-temps-attente-agences-api, kafka, zookeeper, kowl) | ||
* 2 fichiers quickstart (.ps1 et .sh) qui effectuent les opérations suivantes avec une pause de 5 secondes entre chaque étape : | ||
|
||
* Exécution du fichier Yaml permettant de télécharger et monter les conteneurs via la commande | ||
```bash | ||
docker-compose | ||
``` | ||
* Vérification de l'existance du topic Kafka "temps-attente. S'il n'existe pas, il est créé.\ | ||
A noter que la création du topic Kafka est réalisée par l'intermétiaire des commandes natives Kafka afin d'assurer la portabilité du script Powershell (Windows/Linux). | ||
* Exécution des 2 routes camel via la commande, qui génére aussi un fichier _camel-output.log_ : | ||
```bash | ||
camel-run | ||
``` | ||
* Lancement de l'interface web de kowl dans le naviguateur par défaut du système d'exploitation | ||
## ℹ️ Mode opératoire | ||
* Lancer un invite de commande (bash, PowerShell, Terminal Windows) | ||
* Se placer dans le dossier _scripts_ | ||
* Exécuter le fichier _.ps1_ pour Windows/Linux (si Powershell est installé) ou _.sh_ pour Linux. | ||
![image](https://github.com/opt-nc/opt-temps-attente-agences-camel/blob/20-fournir-quickstartmd/doc/shell.png) | ||
A noter qu'il sera sans doute nécessaire d'actualiser la page Kowl pour que le flux de données soit visible. | ||
![image](https://github.com/opt-nc/opt-temps-attente-agences-camel/blob/20-fournir-quickstartmd/doc/kowl.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,49 @@ | ||
Write-Output "Début du script" | ||
|
||
## Variables | ||
$BROKER="localhost:9092" | ||
$TOPIC="temps-attente" | ||
# URL Kowl | ||
$URL = "http://localhost:8888/topics/"+$TOPIC+"?o=-1&p=-1&s=50#messages" | ||
|
||
# Exécute docker-compose pour démarrer les conteneurs | ||
Write-Output "Lancement des conteneurs" | ||
docker-compose -f temps_attente.yml up -d | ||
|
||
# ajouter un temps de pause de 5 secondes | ||
Start-Sleep -Seconds 5 | ||
|
||
Write-Output "Vérification de l'existance du topic Kafka $TOPIC" | ||
# vérifier si le topic existe | ||
if (docker exec -it kafka kafka-topics.sh --bootstrap-server $BROKER --list | Select-String -Pattern "$TOPIC") { | ||
Write-Output "Le topic $TOPIC existe déjà." | ||
} else { | ||
# créer un nouveau topic | ||
#docker exec -it kafka kafka-console-producer.sh --broker-list $BROKER --topic $TOPIC | ||
docker exec -it kafka kafka-topics.sh --bootstrap-server $BROKER --create --topic $TOPIC --partitions 1 --replication-factor 1 | ||
|
||
|
||
# vérifier si la création du topic est réussie | ||
if ($LASTEXITCODE -eq 0) { | ||
Write-Output "Le topic $TOPIC a été créé avec succès." | ||
} else { | ||
Write-Output "La création du topic $TOPIC a échoué." | ||
} | ||
} | ||
|
||
# ajouter un temps de pause de 5 secondes | ||
Start-Sleep -Seconds 5 | ||
|
||
Write-Output "Lancement de la route Camel API temps d'attente vers Kafka" | ||
# Exécute Camel pour démarrer les routes Kafka | ||
#camel run route-kafka.xml route-kafka-json.xml --dep camel.dependencies=org.apache.camel:camel-kafka > camel-output.log & | ||
camel run route-kafka.xml route-kafka-json.xml --dep camel.dependencies=org.apache.camel:camel-kafka > camel-output.log & | ||
# Affiche le PID du processus Camel | ||
Write-Output "Le PID du processus Camel est : $PID" | ||
Write-Output "Fin du script" | ||
|
||
# ajouter un temps de pause de 5 secondes | ||
Start-Sleep -Seconds 5 | ||
|
||
# Lancement de la page Kowl | ||
Start-Process -FilePath $URL |
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 @@ | ||
#!/bin/bash | ||
|
||
# Variables | ||
BROKER="localhost:9092" | ||
TOPIC="temps-attente" | ||
# URL Kowl | ||
URL="http://localhost:8888/topics/$TOPIC?o=-1&p=-1&s=50#messages" | ||
|
||
# Exécute docker-compose pour démarrer les conteneurs | ||
echo "Lancement des conteneurs" | ||
docker-compose -f temps_attente.yml up -d | ||
|
||
# ajouter un temps de pause de 5 secondes | ||
sleep 5 | ||
|
||
echo "Vérification de l'existance du topic Kafka $TOPIC" | ||
# vérifier si le topic existe | ||
if docker exec -it kafka kafka-topics.sh --bootstrap-server $BROKER --list | grep -q "$TOPIC"; then | ||
echo "Le topic $TOPIC existe déjà." | ||
else | ||
# créer un nouveau topic | ||
#docker exec -it kafka kafka-console-producer.sh --broker-list $BROKER --topic $TOPIC | ||
docker exec -it kafka kafka-topics.sh --bootstrap-server $BROKER --create --topic $TOPIC --partitions 1 --replication-factor 1 | ||
|
||
# vérifier si la création du topic est réussie | ||
if [ $? -eq 0 ]; then | ||
echo "Le topic $TOPIC a été créé avec succès." | ||
else | ||
echo "La création du topic $TOPIC a échoué." | ||
fi | ||
fi | ||
|
||
# ajouter un temps de pause de 5 secondes | ||
sleep 5 | ||
|
||
echo "Lancement de la route Camel API temps d'attente vers Kafka" | ||
# Exécute Camel pour démarrer les routes Kafka | ||
camel run route-kafka.xml route-kafka-json.xml --dep camel.dependencies=org.apache.camel:camel-kafka > camel-output.log & PID=$! | ||
# Affiche le PID du processus Camel | ||
echo "Le PID du processus Camel est : $PID" | ||
echo "Fin du script" | ||
|
||
# ajouter un temps de pause de 5 secondes | ||
sleep 5 | ||
|
||
# Lancement de la page Kowl | ||
xdg-open $URL |
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,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- camel-k: language=xml --> | ||
|
||
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://camel.apache.org/schema/spring" | ||
xsi:schemaLocation=" | ||
http://camel.apache.org/schema/spring | ||
https://camel.apache.org/schema/spring/camel-spring.xsd"> | ||
|
||
<!-- Write your routes here, for example: --> | ||
<route id="kafka-get-route"> | ||
|
||
<!-- URL source Kafka et indication du groupid --> | ||
<from uri="kafka:temps-attente?brokers=localhost:9092&groupId=temps-attente"/> | ||
|
||
<!-- Déserialisation des données au format JSON --> | ||
<unmarshal> | ||
<json library="Jackson" prettyPrint="true" /> | ||
</unmarshal> | ||
|
||
<!-- Affichage du JSON dans le terminal --> | ||
<log message="Received data: ${body}" loggingLevel="DEBUG"/> | ||
|
||
<!-- Conversion des données au format CSV --> | ||
<marshal> | ||
<json library="Jackson" prettyPrint="true" /> | ||
</marshal> | ||
|
||
<!-- Route de destination du fichier avec ajout des données à la fin du csv--> | ||
<to uri="file:./files?fileExist=Append&fileName=temps-attente.json"/> | ||
|
||
<!-- Affichage du CSV dans le terminal --> | ||
<log message="Received data: ${body}" loggingLevel="DEBUG"/> | ||
|
||
</route> | ||
</routes> |
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,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- camel-k: language=xml --> | ||
|
||
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://camel.apache.org/schema/spring" | ||
xsi:schemaLocation=" | ||
http://camel.apache.org/schema/spring | ||
https://camel.apache.org/schema/spring/camel-spring.xsd"> | ||
|
||
<!-- Write your routes here, for example: --> | ||
<route id="http-get-route"> | ||
|
||
<!-- Ordonnance de l'exécution de la route toutes les 5 minutes --> | ||
<from uri="timer:http-get-timer??period={{time:300000}}"/> | ||
|
||
<!-- URL source de l'API avec la méthode GET --> | ||
<to uri="http://localhost:8080/temps-attente/agences?httpMethod=GET"/> | ||
|
||
<!-- Déserialisation des données au format JSON --> | ||
<unmarshal> | ||
<json library="Jackson" prettyPrint="false" /> | ||
</unmarshal> | ||
|
||
<!-- JSON --> | ||
<!-- Conversion des données au format JSON --> | ||
<marshal> | ||
<json library="Jackson" prettyPrint="false" /> | ||
</marshal> | ||
|
||
<!-- URL de destination Kafka et paramétrage de la clé --> | ||
<to uri="kafka:temps-attente?brokers=localhost:9092&key=idAgence"/> | ||
|
||
</route> | ||
</routes> |
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,48 @@ | ||
version: "3" | ||
|
||
services: | ||
optnc : | ||
hostname : optnc | ||
image : optnc/opt-temps-attente-agences-api | ||
container_name: optnc | ||
ports: | ||
- "8080:8080" | ||
|
||
zookeeper: | ||
hostname : zookeeper | ||
image: docker.io/bitnami/zookeeper:latest | ||
container_name: zookeeper | ||
ports: | ||
- "2181:2181" | ||
healthcheck: | ||
test: ["CMD", "echo", "ruok"] | ||
interval: 30s | ||
timeout: 5s | ||
retries: 3 | ||
environment: | ||
- ALLOW_ANONYMOUS_LOGIN=yes | ||
|
||
kafka: | ||
hostname : kafka | ||
image: docker.io/bitnami/kafka:latest | ||
container_name: kafka | ||
ports: | ||
- "9092:9092" | ||
- "9093:9093" | ||
depends_on: | ||
- zookeeper | ||
environment: | ||
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181 | ||
- ALLOW_PLAINTEXT_LISTENER=yes | ||
|
||
kowl: | ||
image: quay.io/cloudhut/kowl:v1.3.1 | ||
container_name: kowl | ||
restart: always | ||
ports: | ||
- "8888:8888" | ||
depends_on: | ||
- kafka | ||
environment: | ||
- KAFKA_BROKERS=kafka:9092 | ||
- SERVER_LISTENPORT=8888 |