You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2021/02/08 09:28:37 UTC

[camel-kafka-connector-examples] branch master updated: Add Twitter Timeline Sink and Source examples

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector-examples.git


The following commit(s) were added to refs/heads/master by this push:
     new 5beed28  Add Twitter Timeline Sink and Source examples
5beed28 is described below

commit 5beed2882927d7b9e20e468a429f3a4ab1337aab
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Mon Feb 8 18:20:05 2021 +0900

    Add Twitter Timeline Sink and Source examples
    
    Fix apache/camel-kafka-connector#640
---
 README.adoc                                        |  1 +
 twitter/twitter-timeline-sink/README.adoc          | 80 ++++++++++++++++++++++
 .../CamelTwittertimelineSinkConnector.properties   | 31 +++++++++
 twitter/twitter-timeline-source/README.adoc        | 80 ++++++++++++++++++++++
 .../CamelTwittertimelineSourceConnector.properties | 31 +++++++++
 5 files changed, 223 insertions(+)

diff --git a/README.adoc b/README.adoc
index b9d0a1f..41573fe 100644
--- a/README.adoc
+++ b/README.adoc
@@ -42,3 +42,4 @@ List of existing examples:
 - Telegram source and sink examples
 - Twitter Direct message source and sink examples
 - Twitter Search source example
+- Twitter Timeline source and sink examples
diff --git a/twitter/twitter-timeline-sink/README.adoc b/twitter/twitter-timeline-sink/README.adoc
new file mode 100644
index 0000000..23035de
--- /dev/null
+++ b/twitter/twitter-timeline-sink/README.adoc
@@ -0,0 +1,80 @@
+= Camel-Kafka-connector Twitter Timeline Sink
+
+This is an example for Camel-Kafka-connector Twitter Timeline Sink
+
+== Standalone
+
+=== What is needed
+
+- A Twitter App with Read and Write permissions
+
+=== Setting up Twitter App and get credentials
+
+You'll need to create a twitter app and take note of access token, access token secret, consumer key and consumer secret.
+
+=== Running Kafka
+
+[source]
+----
+$KAFKA_HOME/bin/zookeeper-server-start.sh $KAFKA_HOME/config/zookeeper.properties
+$KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties
+$KAFKA_HOME/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic mytopic
+----
+
+=== Setting up the needed bits and running the example
+
+You'll need to setup the plugin.path property in your kafka
+
+Open the `$KAFKA_HOME/config/connect-standalone.properties`
+
+and set the `plugin.path` property to your choosen location
+
+In this example we'll use `/home/oscerd/connectors/`
+
+[source]
+----
+> cd /home/oscerd/connectors/
+> wget https://repo1.maven.org/maven2/org/apache/camel/kafkaconnector/camel-twitter-timeline-kafka-connector/0.7.1/camel-twitter-timeline-kafka-connector-0.7.1-package.zip
+> unzip camel-twitter-timeline-kafka-connector-0.7.1-package.zip
+----
+
+Now it's time to setup the connectors
+
+Open the Twitter sink configuration file
+
+[source]
+----
+name=CamelTwitter-timelineSinkConnector
+connector.class=org.apache.camel.kafkaconnector.twittertimeline.CamelTwittertimelineSinkConnector
+tasks.max=1
+key.converter=org.apache.kafka.connect.storage.StringConverter
+value.converter=org.apache.kafka.connect.storage.StringConverter
+
+topics=mytopic
+
+camel.sink.path.timelineType=user
+camel.sink.endpoint.user=<user_id>
+camel.sink.endpoint.accessToken=<access_token>
+camel.sink.endpoint.accessTokenSecret=<access_token_secret>
+camel.sink.endpoint.consumerKey=<consumer_key>
+camel.sink.endpoint.consumerSecret=<consumer_secret>
+----
+
+Set the correct options in the file for the credentials part.
+
+Now you can run the example
+
+[source]
+----
+$KAFKA_HOME/bin/connect-standalone.sh $KAFKA_HOME/config/connect-standalone.properties config/CamelTwittertimelineSinkConnector.properties
+----
+
+In another terminal, using kafkacat, you can produce a message
+
+[source]
+----
+> echo "Hello from ckc" | ./kafkacat -b localhost:9092 -t mytopic
+% Auto-selecting Producer mode (use -P or -C to override)
+----
+
+The user should now post a tweet with "Hello from ckc" as body
diff --git a/twitter/twitter-timeline-sink/config/CamelTwittertimelineSinkConnector.properties b/twitter/twitter-timeline-sink/config/CamelTwittertimelineSinkConnector.properties
new file mode 100644
index 0000000..2251198
--- /dev/null
+++ b/twitter/twitter-timeline-sink/config/CamelTwittertimelineSinkConnector.properties
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+name=CamelTwitter-timelineSinkConnector
+connector.class=org.apache.camel.kafkaconnector.twittertimeline.CamelTwittertimelineSinkConnector
+tasks.max=1
+key.converter=org.apache.kafka.connect.storage.StringConverter
+value.converter=org.apache.kafka.connect.storage.StringConverter
+
+topics=mytopic
+
+camel.sink.path.timelineType=user
+camel.sink.endpoint.user=<user_id>
+camel.sink.endpoint.accessToken=<access_token>
+camel.sink.endpoint.accessTokenSecret=<access_token_secret>
+camel.sink.endpoint.consumerKey=<consumer_key>
+camel.sink.endpoint.consumerSecret=<consumer_secret>
diff --git a/twitter/twitter-timeline-source/README.adoc b/twitter/twitter-timeline-source/README.adoc
new file mode 100644
index 0000000..2de1fac
--- /dev/null
+++ b/twitter/twitter-timeline-source/README.adoc
@@ -0,0 +1,80 @@
+= Camel-Kafka-connector Twitter Timeline Source
+
+This is an example for Camel-Kafka-connector Twitter Timeline Source
+
+== Standalone
+
+=== What is needed
+
+- A Twitter App with Read and Write permissions
+
+=== Setting up Twitter App and get credentials
+
+You'll need to create a twitter app and take note of access token, access token secret, consumer key and consumer secret.
+
+=== Running Kafka
+
+[source]
+----
+$KAFKA_HOME/bin/zookeeper-server-start.sh $KAFKA_HOME/config/zookeeper.properties
+$KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties
+$KAFKA_HOME/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic mytopic
+----
+
+=== Setting up the needed bits and running the example
+
+You'll need to setup the plugin.path property in your kafka
+
+Open the `$KAFKA_HOME/config/connect-standalone.properties`
+
+and set the `plugin.path` property to your choosen location
+
+In this example we'll use `/home/oscerd/connectors/`
+
+[source]
+----
+> cd /home/oscerd/connectors/
+> wget https://repo1.maven.org/maven2/org/apache/camel/kafkaconnector/camel-twitter-timeline-kafka-connector/0.7.1/camel-twitter-timeline-kafka-connector-0.7.1-package.zip
+> unzip camel-twitter-timeline-kafka-connector-0.7.1-package.zip
+----
+
+Now it's time to setup the connectors
+
+Open the Twitter source configuration file
+
+[source]
+----
+name=CamelTwitter-timelineSourceConnector
+connector.class=org.apache.camel.kafkaconnector.twittertimeline.CamelTwittertimelineSourceConnector
+tasks.max=1
+key.converter=org.apache.kafka.connect.storage.StringConverter
+value.converter=org.apache.kafka.connect.storage.StringConverter
+
+topics=mytopic
+
+camel.source.path.timelineType=user
+camel.source.endpoint.user=ApacheCamel
+camel.source.endpoint.accessToken=<access_token>
+camel.source.endpoint.accessTokenSecret=<access_token_secret>
+camel.source.endpoint.consumerKey=<consumer_key>
+camel.source.endpoint.consumerSecret=<consumer_secret>
+----
+
+Set the correct options in the file for the credentials part.
+
+Now you can run the example
+
+[source]
+----
+$KAFKA_HOME/bin/connect-standalone.sh $KAFKA_HOME/config/connect-standalone.properties config/CamelTwittertimelineSourceConnector.properties
+----
+
+In another terminal, using kafkacat, you can consume the messages
+
+[source]
+----
+> ./kafkacat -b localhost:9092 -t mytopic
+% Auto-selecting Consumer mode (use -P or -C to override)
+StatusJSONImpl{createdAt=Thu Jan 21 19:40:53 UTC 2021, id=1352340411239559170, text='We released Apache Camel 3.7.1 (LTS) today, a new patch release with 29 fixes and improvements: https://t.co/osOTD4uY5k #apachecamel', source='<a href="https://about.twitter.com/products/tweetdeck" rel="nofollow">TweetDeck</a>', isTruncated=false, inReplyToStatusId=-1, inReplyToUserId=-1, isFavorited=false, isRetweeted=false, favoriteCount=37, inReplyToScreenName='null', geoLocation=null, place=null, ret [...]
+% Reached end of topic mytopic [0] at offset 1
+----
diff --git a/twitter/twitter-timeline-source/config/CamelTwittertimelineSourceConnector.properties b/twitter/twitter-timeline-source/config/CamelTwittertimelineSourceConnector.properties
new file mode 100644
index 0000000..f6a3062
--- /dev/null
+++ b/twitter/twitter-timeline-source/config/CamelTwittertimelineSourceConnector.properties
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+name=CamelTwitter-timelineSourceConnector
+connector.class=org.apache.camel.kafkaconnector.twittertimeline.CamelTwittertimelineSourceConnector
+tasks.max=1
+key.converter=org.apache.kafka.connect.storage.StringConverter
+value.converter=org.apache.kafka.connect.storage.StringConverter
+
+topics=mytopic
+
+camel.source.path.timelineType=user
+camel.source.endpoint.user=ApacheCamel
+camel.source.endpoint.accessToken=<access_token>
+camel.source.endpoint.accessTokenSecret=<access_token_secret>
+camel.source.endpoint.consumerKey=<consumer_key>
+camel.source.endpoint.consumerSecret=<consumer_secret>