-
Notifications
You must be signed in to change notification settings - Fork 40
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 #25 from Shiti/develop
Example using source and sink
- Loading branch information
Showing
8 changed files
with
223 additions
and
38 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
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
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,4 @@ | ||
name=cassandra-source-bulk | ||
connector.class=com.tuplejump.kafka.connect.cassandra.CassandraSource | ||
topic=demo | ||
cassandra.source.route.demo=select * from demo.event_store |
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,5 @@ | ||
name=cassandra-sink-connector | ||
connector.class=com.tuplejump.kafka.connect.cassandra.CassandraSink | ||
tasks.max=1 | ||
topics=demo | ||
cassandra.sink.route.demo=demo.event_store_sink |
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,40 @@ | ||
website,annual,purchase,1457713158000 | ||
iphone,monthly,others,1457713159000 | ||
android,trial,purchase,1457713160000 | ||
website,monthly,renewal,1457713161000 | ||
website,monthly,others,1457713162000 | ||
android,monthly,feedback,1457713163000 | ||
iphone,annual,enquiry,1457713164000 | ||
iphone,monthly,purchase,1457713165000 | ||
website,trial,others,1457713166000 | ||
android,none,feedback,1457713167000 | ||
android,annual,renewal,1457713168000 | ||
iphone,none,others,1457713169000 | ||
android,annual,purchase,1457713170000 | ||
website,trial,renewal,1457713171000 | ||
iphone,none,others,1457713172000 | ||
android,trial,purchase,1457713173000 | ||
iphone,annual,others,1457713174000 | ||
android,monthly,renewal,1457713175000 | ||
iphone,monthly,renewal,1457713176000 | ||
website,trial,feedback,1457713177000 | ||
iphone,monthly,renewal,1457713321000 | ||
android,annual,feedback,1457713322000 | ||
android,none,feedback,1457713323000 | ||
website,none,enquiry,1457713324000 | ||
website,none,feedback,1457713325000 | ||
website,monthly,enquiry,1457713326000 | ||
website,trial,enquiry,1457713327000 | ||
android,none,renewal,1457713328000 | ||
website,monthly,purchase,1457713329000 | ||
iphone,annual,purchase,1457713330000 | ||
website,annual,others,1457713331000 | ||
website,monthly,enquiry,1457713332000 | ||
android,trial,purchase,1457713333000 | ||
iphone,none,enquiry,1457713334000 | ||
iphone,annual,enquiry,1457713335000 | ||
website,none,feedback,1457713336000 | ||
iphone,trial,enquiry,1457713337000 | ||
website,monthly,renewal,1457713338000 | ||
android,none,enquiry,1457713339000 | ||
android,monthly,purchase,1457713340000 |
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 @@ | ||
CREATE KEYSPACE IF NOT EXISTS demo WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }; | ||
|
||
USE demo; | ||
|
||
CREATE TABLE IF NOT EXISTS demo.event_store( | ||
app_id text, | ||
event_type text, | ||
subscription_type text, | ||
event_ts timestamp, | ||
PRIMARY KEY((app_id, event_type), event_ts) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS demo.event_store_sink( | ||
app_id text, | ||
event_type text, | ||
subscription_type text, | ||
event_ts timestamp, | ||
PRIMARY KEY((app_id, event_type), event_ts) | ||
); | ||
|
||
COPY event_store(app_id,subscription_type,event_type,event_ts) FROM 'data.csv' ; | ||
|
||
|
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,79 @@ | ||
#!/usr/bin/env bash | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
waitForStart(){ | ||
until grep -q "$2" $3 | ||
do | ||
echo "waiting for "$1" to start" | ||
sleep 5 | ||
done | ||
} | ||
|
||
if [ ! -f "$KAFKA_HOME" ] | ||
then | ||
if [ ! -f kafka.tgz ] | ||
then | ||
echo "KAFKA_HOME is not configured. Downloading Kafka." | ||
wget "http://archive.apache.org/dist/kafka/0.9.0.1/kafka_2.11-0.9.0.1.tgz" -O kafka.tgz | ||
fi | ||
tar -xzf kafka.tgz | ||
KAFKA_HOME=$DIR/$(tar tfz kafka.tgz --exclude '*/*') | ||
fi | ||
|
||
if [ ! -f "$CASSANDRA_HOME" ] | ||
then | ||
if [ ! -f cassandra.tar.gz ] | ||
then | ||
echo "CASSANDRA_HOME is not configured. Downloading Cassandra." | ||
wget "http://archive.apache.org/dist/cassandra/3.1.1/apache-cassandra-3.1.1-bin.tar.gz" -O cassandra.tar.gz | ||
fi | ||
mkdir -p cassandra | ||
tar -xzf cassandra.tar.gz -C cassandra --strip-components=1 | ||
CASSANDRA_HOME=cassandra | ||
fi | ||
|
||
if [ ! -f "kafka-connect-cassandra-assembly-0.0.7.jar" ] | ||
then | ||
echo "didnt find jar. Downloading" | ||
wget "http://downloads.tuplejump.com/kafka-connect-cassandra-assembly-0.0.7.jar" | ||
fi | ||
|
||
cp kafka-connect-cassandra-assembly-0.0.7.jar ${KAFKA_HOME}libs/ | ||
|
||
##update path of data file | ||
sed -i "s;'data.csv';'${DIR}/data.csv';" "${DIR}/setup.cql" | ||
|
||
##start cassandra | ||
cd ${CASSANDRA_HOME} | ||
|
||
bin/cassandra -p ${DIR}/'demo.pid' > ${DIR}/cassandraLog | ||
|
||
waitForStart "cassandra" "state jump to NORMAL" "${DIR}/cassandraLog" | ||
|
||
##setup schema | ||
bin/cqlsh -f "${DIR}/setup.cql" | ||
|
||
cd ${KAFKA_HOME} | ||
|
||
## start zookeeper | ||
bin/zookeeper-server-start.sh config/zookeeper.properties > ${DIR}/zkLog & | ||
ZK_PID=$! | ||
|
||
waitForStart "zookeeper" "binding to port" "${DIR}/zkLog" | ||
echo -n " "${ZK_PID} >> ${DIR}/demo.pid | ||
|
||
## start Kafka server | ||
bin/kafka-server-start.sh config/server.properties > ${DIR}/serverLog & | ||
KAFKA_PID=$! | ||
|
||
waitForStart "kafka server" "Awaiting socket connections" "${DIR}/serverLog" | ||
echo -n " "${KAFKA_PID} >> ${DIR}/demo.pid | ||
|
||
# create topic | ||
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic demo | ||
|
||
bin/connect-standalone.sh config/connect-standalone.properties ${DIR}/config/bulk-source.properties ${DIR}/config/sink.properties > ${DIR}/connectLog & | ||
CONNECT_PID=$! | ||
|
||
echo -n " "${CONNECT_PID} >> ${DIR}/demo.pid |
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,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ -f "demo.pid" ] | ||
then | ||
kill -9 $(cat demo.pid) | ||
rm demo.pid | ||
fi |