An easy way to create large dataset when playing/demonstrating Couchbase -or any other NoSQL engine- is to inject Twitter feed into your database.
For this small application I am using:
- Couchbase Server 2.0 Server
- Couchbase Java SDK (will be installed by Maven)
- Twitter4J (will be installed by Maven)
- Twitter Streaming API called using Twitter4J
The sources of this project are available on my Github repository Twitter Injector for Couchbase you can also download the Binary version here, and execute the application from the command line, see Run The Application paragraph. Do not forget to create your Twitter oAuth keys (see next paragraph)
- Consumer key
- Consumer secret
- Access token
- Access token secret
Some basic explanation:
- The setUp() method simply reads the twitter4j.properties file from the classpath to build the Couchbase connection string.
- The injectTweets opens the Couchbase connection -line 76- and calls the TwitterStream API.
- A Listener is created and will receive all the onStatus(Status status) from Twitter. The most important method is onStatus() that receive the message and save it into Couchbase.
- One interesting thing : since Couchbase is a JSON Document database it allows your to just take the JSON String and save it directly.
... com.couchbase.demo.TwitterInjector .
- The mainClass entry allows you to set which class to execute when running java -jar command.
- The Class-Path entry allows you to set the current directory as part of the classpath where the program will search for the twitter4j.properties file.
- The assembly file is also configure to include all the dependencies (Twitter4J, Couchbase client SDK, ...)
mvn clean package
Run the Java Application
Before running the application you must create a twitter4j.properties file with the following information :
twitter4j.jsonStoreEnabled=true oauth.consumerKey=[YOUR CONSUMER KEY] oauth.consumerSecret=[YOUR CONSUMER SECRET KEY] oauth.accessToken=[YOUR ACCESS TOKEN] oauth.accessTokenSecret=[YOUR ACCESS TOKEN SECRET] couchbase.uri.list=http://127.0.0.1:8091/pools couchbase.bucket=default couchbase.password=
Save the properties file and from the same location run:
jar -jar [path-to-jar]/CouchbaseTwitterInjector.jar