Skip to Content
Apache Spark によるストリーム処理
book

Apache Spark によるストリーム処理

by Gerard Maas, Francois Garillot
May 2025
Intermediate to advanced
452 pages
6h 3m
Japanese
O'Reilly Media, Inc.
Content preview from Apache Spark によるストリーム処理

第19章. Sparkストリーミング・ソース

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

第2章で学んだように、ストリーミングソースは継続的にデータを配信するデータプロバイダである。 Spark Streamingでは、ソースはSpark Streamingジョブのコンテキスト内で実行されるアダプタであり、外部ストリーミングソースとのインタラクションを実装し、DStream抽象化を使用してSpark Streamingにデータを提供する。 プログラミングの観点から、ストリーミングデータソースを消費することは、対応するソースの適切な実装を使用してDStreamを作成することを意味する。

DStream抽象化 "では、ネットワークソケットからデータを消費する例を見た。例 19-1でその例をもう一度見てみよう。

例 19-1. ソケット接続からテキストストリームを作成する
// creates a DStream using a client socket connected to the given host and port
val textDStream: DStream[String] = ssc.socketTextStream("localhost", 9876)

例 19-1 では、ストリーミングソースの作成は専用の実装によって提供されることがわかる。 この場合、ストリーミングコンテキストであるssc インスタンスによって提供され、DStream の内容で型付けされたソケットから配信されたテキストデータを含むDStream[String] が生成される。 ソースごとに実装は異なるが、このパターンはすべて同じである。ソースの作成にはstreamingContext が必要であり、その結果、ストリームの内容を表す DStream が生成される。ストリーミングアプリケーションはさらに、生成された DStream を演算子として、ジョブの論理を実装する。

情報源の種類

汎用的なストリーム処理フレームワークであるSpark Streamingは、多種多様なストリーミングデータソースと統合することができる。

演算子によって分類すると、3種類のソースがある:

  • ベーシック

  • レシーバー・ベース

  • ディレクトリ

基本的な情報源

基本ソースは、streamingContext によってネイティブに提供される。 これらは主にサンプルまたはテスト・ソースとして提供され、障害回復セマンティクスは提供されない。 したがって、本番システムで使用することは推奨されない。

以下は基本的な情報源である:

ファイルソース

、ファイルシステムのディレクトリを監視し、新しいファイルを読み取るために使用される。ファイルは、特にデータウェアハウスや多くのデータレイクの実装のような、バッチベースの統合モデルから進化したシステムにおいて、システム間でデータを通信するための広範なメカニズムである。

キューソース

Spark Streamingにデータを注入するために使用できる、streamingContext にローカルなプロデューサ-コンシューマキュー。通常、テストに使用される。

ConstantInputDStream正式にはソースではないが、キュー・ソースと似たような関数を実行する。

受信機ベースのソース

18章で説明したように、レシーバーはSpark Streamingの特殊化プロセスであり、ストリーミングソースからデータを受け取り、RDDの形式でSparkに信頼性の高い方法で配信する役割を担う。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Apache Flinkによるストリーム処理

Apache Flinkによるストリーム処理

Fabian Hueske, Vasiliki Kalavri

Publisher Resources

ISBN: 9798341650602