/**
* 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.
*/
package org.apache.camel.example.websocket;
import org.apache.camel.main.Main;
/**
* A main to start this example.
*/
public final class CamelTwitterWebSocketMain {
// Twitter now requires the use of OAuth for all client application authentication.
// In order to use camel-twitter with your account, you'll need to create a new application
// within Twitter at https://dev.twitter.com/apps/new and grant the application access to your account.
// Finally, generate your access token and secret.
// This uses the Twitter 'cameltweet' account for testing purposes.
// do NOT use this twitter account in your applications!
private static String consumerKey = "NMqaca1bzXsOcZhP2XlwA";
private static String consumerSecret = "VxNQiRLwwKVD0K9mmfxlTTbVdgRpriORypnUbHhxeQw";
private static String accessToken = "26693234-W0YjxL9cMJrC0VZZ4xdgFMymxIQ10LeL1K8YlbBY";
private static String accessTokenSecret = "BZD51BgzbOdFstWZYsqB5p5dbuuDV12vrOdatzhY4E";
private CamelTwitterWebSocketMain() {
// to pass checkstyle we have a private constructor
}
public static void main(String[] args) throws Exception {
System.out.println("\n\n\n\n");
System.out.println("===============================================");
System.out.println("Open your web browser on http://localhost:9090/index.html");
System.out.println("Press ctrl+c to stop this example");
System.out.println("===============================================");
System.out.println("\n\n\n\n");
// create a new Camel Main so we can easily start Camel
Main main = new Main();
TwitterWebSocketRoute route = new TwitterWebSocketRoute();
// setup twitter application authentication
route.setAccessToken(accessToken);
route.setAccessTokenSecret(accessTokenSecret);
route.setConsumerKey(consumerKey);
route.setConsumerSecret(consumerSecret);
// poll for gaga, every 5nd second
// twitter rate limits 180 per 15 min, so that is 0.2/sec, eg 1/5sec.
// so to be safe we do 6 seconds
route.setSearchTerm("gaga");
route.setDelay(6000);
// web socket on port 9090
route.setPort(9090);
// add our routes to Camel
main.addRouteBuilder(route);
// and run, which keeps blocking until we terminate the JVM (or stop CamelContext)
main.run();
}
}