# ほぼリアルタイムでTwitterの流れを分析する

このシナリオは、Talend Real-Time Big Data PlatformとTalend Data Fabricにのみ適用されます。

このシナリオでは、Spark Streamingジョブを作成して、各15秒間隔の最後に、Twitterユーザーが前回の20秒間に自分のツイートでパリに言及した際に最もよく使用しているハッシュタグを分析します。

![](https://help.qlik.com/talend/ja-JP/components/8.0/Resources/images/use_case-tkafkainput_twitter1.png)

たとえば、オープンソースのサードパーティプログラムを使用して、特定のKafkaトピック*twitter\_live*でTwitterストリームを送受信し、このトピックのツイートを使用するためにこのシナリオで設計したジョブを使用します。

ハッシュタグ付きのTwitter生データの行は、https://dev.twitter.com/overview/api/entities-in-twitter-objects#hashtagsで示されている例のように読み取られます。

このシナリオを複製する前に、Kafkaシステムが稼動していること、また、使用するKafkaトピックにアクセスするための適切な権限とアクセス権があることを確認します。また、TwitterストリームをほぼリアルタイムでKafkaに転送するには、Twitterストリーミングプログラムが必要です。 *Talend* は、この種のプログラムを提供していませんが、この目的のために作成されたいくつかの無料のプログラムがGithubなどの一部のオンラインコミュニティから入手できます。

tHDFSConfigurationはこのシナリオで、ジョブに依存するjarファイルの転送先となるHDFSシステムに接続するために、Sparkによって使用されます。

[Run] (実行)ビューの[Spark configuration] (Spark設定)タブで、ジョブ全体でのSparkクラスターへの接続を定義します。また、ジョブでは、依存jarファイルを実行することを想定しているため、Sparkがこれらのjarファイルにアクセスできるように、これらのファイルの転送先にするファイルシステム内のディレクトリーを指定する必要があります。

* Yarnモード(YarnクライアントまたはYarnクラスター):

  * Google Dataprocを使用している場合、[Spark configuration] (Spark設定)タブの[Google Storage staging bucket] (Google Storageステージングバケット)フィールドにバケットを指定します。

  * HDInsightを使用している場合、[Spark configuration] (Spark設定)タブの[Windows Azure Storage configuration] (Windows Azure Storage設定)エリアでジョブのデプロイメントに使用するブロブを指定します。

  * Altusを使用する場合は、[Spark configuration] (Spark設定)タブでジョブのデプロイにS3バケットまたはAzure Data Lake Storageを指定します。

  * オンプレミスのディストリビューションを使用する場合は、クラスターで使われているファイルシステムに対応する設定コンポーネントを使用します。一般的に、このシステムはHDFSになるため、[tHDFSConfiguration](https://help.qlik.com/talend/r/ja-JP/8.0/components/hdfs/thdfsconfiguration)を使用します。

* [Standalone mode] (スタンドアロンモード): クラスターで使われているファイルシステム([tHDFSConfiguration Apache Spark Batch](https://help.qlik.com/talend/r/ja-JP/8.0/components/hdfs/thdfsconfiguration-properties-for-apache-spark-batch)や[tS3Configuration Apache Spark Batch](https://help.qlik.com/talend/r/ja-JP/8.0/components/amazon-s3/ts3configuration-properties-for-apache-spark-batch)など)に対応する設定コンポーネントを使用します。

  ジョブ内に設定コンポーネントがない状態でDatabricksを使用している場合、ビジネスデータはDBFS (Databricks Filesystem)に直接書き込まれます。

このシナリオを複製するには、次の手順に従います。

### このセクション内

* [コンポーネントをリンク](https://help.qlik.com/talend/ja-JP/components/8.0/spark-streaming/tkafkainput-tkafkacreatetopic-thdfsconfiguration-ts3configuration-linking-components-spark-stream-component-in?id=4613)
* [Sparkモードの選択](https://help.qlik.com/talend/ja-JP/components/8.0/spark-streaming/selecting-spark-mode-spark-batch?id=4614)
* [Sparkが使用するファイルシステムに接続を設定](https://help.qlik.com/talend/ja-JP/components/8.0/spark-streaming/configuring-connection-to-file-system-to-be-used-by-spark?id=4616)
* [特定のKafkaトピックからメッセージを読み取る](https://help.qlik.com/talend/ja-JP/components/8.0/spark-streaming/tkafkainput-tkafkacreatetopic-thdfsconfiguration-ts3configuration-reading-messages-from-given-kafka-topic-spark-stream-component?id=4617)
* [ツイートが分析される頻度を設定](https://help.qlik.com/talend/ja-JP/components/8.0/spark-streaming/tkafkainput-tkafkacreatetopic-thdfsconfiguration-ts3configuration-configuring-how-frequent-tweets-are-analyzed-spark-stream-component?id=4618)
* [RAWツイートデータからハッシュタグフィールドを抽出](https://help.qlik.com/talend/ja-JP/components/8.0/spark-streaming/tkafkainput-tkafkacreatetopic-thdfsconfiguration-ts3configuration-extracting-hashtag-field-from-raw-tweet-data-spark-stream-component?id=4619)
* [各ハッシュタグを小文字に揃える](https://help.qlik.com/talend/ja-JP/components/8.0/spark-streaming/tkafkainput-tkafkacreatetopic-thdfsconfiguration-ts3configuration-aligning-each-hashtag-to-lower-case-spark-stream-component?id=4620)
* [各ハッシュタグの出現回数をカウント](https://help.qlik.com/talend/ja-JP/components/8.0/spark-streaming/tkafkainput-tkafkacreatetopic-thdfsconfiguration-ts3configuration-counting-occurrences-of-each-hashtag-spark-stream-component?id=4621)
* [20秒ごとに最も使用頻度の高い5つのハッシュタグを選択](https://help.qlik.com/talend/ja-JP/components/8.0/spark-streaming/tkafkainput-tkafkacreatetopic-thdfsconfiguration-ts3configuration-selecting-5-most-used-hashtags-in-each-20-seconds-spark-stream-component?id=4622)
* [ジョブを実行](https://help.qlik.com/talend/ja-JP/components/8.0/spark-streaming/tkafkainput-tkafkacreatetopic-thdfsconfiguration-ts3configuration-executing-job-spark-stream-component-then-you?id=4623)

**関連概念**

* [tKafkaInput](https://help.qlik.com/talend/ja-JP/components/8.0/spark-streaming/tkafkainput "処理する必要のあるメッセージを、設計しているジョブ内の後に続くコンポーネントに送信します。")

**関連資料**

* [tKafkaCreateTopic](https://help.qlik.com/talend/ja-JP/components/8.0/spark-streaming/tkafkacreatetopic "他のKafkaコンポーネントが使えるKafkaトピックを作成します。")

**関連情報**

* [tHDFSConfiguration](https://help.qlik.com/talend/r/ja-JP/8.0/components/hdfs/thdfsconfiguration)
* [tWindow](https://help.qlik.com/talend/r/ja-JP/8.0/components/processing/twindow)
* [tMap](https://help.qlik.com/talend/r/ja-JP/8.0/components/tmap/tmap)
* [tAggregateRow](https://help.qlik.com/talend/r/ja-JP/8.0/components/processing/taggregaterow)
* [tTop](https://help.qlik.com/talend/r/ja-JP/8.0/components/processing/ttop)
* [tExtractJSONFields](https://help.qlik.com/talend/r/ja-JP/8.0/components/processing/textractjsonfields)
* [tLogRow](https://help.qlik.com/talend/r/ja-JP/8.0/components/logs-and-errors/tlogrow)
* [tS3Configuration](https://help.qlik.com/talend/r/ja-JP/8.0/components/amazon-s3/ts3configuration)