forked from kevin-crook-ucb/ucb_w205_crook_supplement
-
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.
- Loading branch information
1 parent
bdf5ba3
commit 143b08c
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
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,95 @@ | ||
# under review - I will remove this once I have verified | ||
|
||
### UCB MIDS W205 - Kevin Crook's supplement for Synchronous Session #9 | ||
|
||
We will try to follow the official slides as close as we can in class. I will post commands here to make them easier for students to copy and paste. | ||
|
||
### Checklist before class and before working on assignments | ||
|
||
Right now, this checklist has things in it we haven't covered yet, so just do what we have covered. | ||
|
||
https://github.com/kevin-crook-ucb/ucb_w205_crook_supplement/blob/master/2019_Summer/synch_session_commands/checklist_b4_class_assignments.md | ||
|
||
### Project 3 - Understanding User Behavior Project | ||
|
||
Assignment-09 - Define your Pipeline | ||
|
||
Assignment-10 - Setup Pipeline, Part 1 | ||
|
||
Assignment-11 - Setup Pipeline, Part 2 | ||
|
||
Assignment-12 - Synthesis Assignment | ||
|
||
### Flask with Kafka | ||
|
||
``` | ||
mkdir ~/w205/flask-with-kafka | ||
cd ~/w205/flask-with-kafka | ||
cp ~/w205/course-content/09-Ingesting-Data/docker-compose.yml . | ||
``` | ||
|
||
Spin up the cluster | ||
``` | ||
docker-compose up -d | ||
``` | ||
|
||
Create a topic events | ||
``` | ||
docker-compose exec kafka kafka-topics --create --topic events --partitions 1 --replication-factor 1 --if-not-exists --zookeeper zookeeper:32181 | ||
``` | ||
|
||
Should show | ||
``` | ||
Created topic "events". | ||
``` | ||
|
||
Flask | ||
Use the python flask library to write our simple API server | ||
``` | ||
cp ~/w205/course-content/09-Ingesting-Data/basic_game_api.py . | ||
``` | ||
|
||
run it via | ||
``` | ||
docker-compose exec mids env FLASK_APP=/w205/flask-with-kafka/basic_game_api.py flask run | ||
``` | ||
|
||
Test it out | ||
``` | ||
docker-compose exec mids curl http://localhost:5000/ | ||
docker-compose exec mids curl http://localhost:5000/purchase_a_sword | ||
``` | ||
|
||
Stop flask | ||
Kill flask with control-C | ||
|
||
Generate events from our webapp | ||
Let's add kafka into the mix | ||
``` | ||
cp ~/w205/course-content/09-Ingesting-Data/game_api.py . | ||
``` | ||
Run that | ||
``` | ||
docker-compose exec mids env FLASK_APP=/w205/flask-with-kafka/game_api.py flask run | ||
``` | ||
|
||
Test it out | ||
Generate events | ||
``` | ||
docker-compose exec mids curl http://localhost:5000/ | ||
docker-compose exec mids curl http://localhost:5000/purchase_a_sword | ||
``` | ||
|
||
read from kafka | ||
Use kafkacat to consume events from the events topic | ||
``` | ||
docker-compose exec mids bash -c "kafkacat -C -b kafka:29092 -t events -o beginning -e" | ||
``` | ||
down | ||
``` | ||
docker-compose down | ||
``` |