For this example, we will use the DataStax Cassandra driver and Akka to build an application that downloads tweets and then stores their ID, text, name, and date in a Cassandra table. Here we will see:
- How to build a simple Akka application with just a few actors
- How to use Akka IO to make HTTP requests
- How to store the data in Cassandra
The first step is to build our core example. It contains three actors: two actors interact with the database and one actor downloads the tweets. The TwitterReadActor
reads from Cassandra, the TweetWriteActor
writes to Cassandra, and the TweetScanActor
downloads the tweets and passes them to the TweetWriteActor
to be written to Cassandra:
class TweetReadActor(cluster: Cluster) extends Actor { ... } class TweetWriterActor(cluster: Cluster) extends Actor { ... } class TweetScanActor(tweetWrite: ActorRef, queryUrl: String => String) extends Actor { ... }
Figure 8-1 shows the relationship between the Twitter downloader...