.authentication(oauth) .eventMessageQueue(eventQueue) .processor(new StringDelimitedProcessor(messageQueue));
/** * @param tweetQueue tweet Queue. * @param hosts Hostes. * @param endpoint Endpoint. * @return Client. */ protected Client buildClient(BlockingQueue<String> tweetQueue, HttpHosts hosts, StreamingEndpoint endpoint) { Authentication authentication = new OAuth1(oAuthSettings.getConsumerKey(), oAuthSettings.getConsumerSecret(), oAuthSettings.getAccessToken(), oAuthSettings.getAccessTokenSecret()); ClientBuilder builder = new ClientBuilder() .name("Ignite-Twitter-Client") .hosts(hosts) .authentication(authentication) .endpoint(endpoint) .processor(new StringDelimitedProcessor(tweetQueue)); return builder.build(); }
public static void run(String consumerKey, String consumerSecret, String token, String secret) throws InterruptedException { BlockingQueue<String> queue = new LinkedBlockingQueue<String>(10000); StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(); // add some track terms endpoint.trackTerms(Lists.newArrayList("twitterapi", "#yolo")); Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret); // Authentication auth = new BasicAuth(username, password); // Create a new BasicClient. By default gzip is enabled. Client client = new ClientBuilder() .hosts(Constants.STREAM_HOST) .endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(queue)) .build(); // Establish a connection client.connect(); // Do whatever needs to be done with messages for (int msgRead = 0; msgRead < 1000; msgRead++) { String msg = queue.take(); System.out.println(msg); } client.stop(); }
.endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(queue)) .build();
.endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(queue)) .build();
.endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(queue)) .build();
private Client getTwitterClient(Properties props, BlockingQueue<String> messageQueue) { String clientName = props.getProperty("clientName"); String consumerKey = props.getProperty("consumerKey"); String consumerSecret = props.getProperty("consumerSecret"); String token = props.getProperty("token"); String tokenSecret = props.getProperty("tokenSecret"); List<String> searchTerms = Arrays.asList(props.getProperty("searchTerms").split(",")); Authentication authentication = new OAuth1(consumerKey,consumerSecret,token,tokenSecret); Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST); StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint(); hosebirdEndpoint.trackTerms(searchTerms); ClientBuilder clientBuilder = new ClientBuilder(); clientBuilder.name(clientName) .hosts(hosebirdHosts) .authentication(authentication) .endpoint(hosebirdEndpoint) .processor(new StringDelimitedProcessor(messageQueue)); return clientBuilder.build(); }
.hosts(Constants.STREAM_HOST).endpoint(hosebirdEndpoint) .authentication(hosebirdAuth) .processor(new StringDelimitedProcessor(msgQueue)).build();
public TwitterConnector(List<String> keywordList, List<Location> locationList, List<String> languageList, String customerKey, String customerSecret, String token, String tokenSecret) throws TexeraException { if ((keywordList == null || keywordList.isEmpty()) && (locationList == null || locationList.isEmpty()) && (languageList == null || languageList.isEmpty())) { throw new DataflowException("no filter is provided"); } //Set up the blocking queue with proper size based on expected TPS of the stream. messageQueue = new LinkedBlockingQueue<String>(queueSize); StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(); if (!(keywordList == null || keywordList.isEmpty())) { endpoint.trackTerms(keywordList); } if (!(locationList == null || locationList.isEmpty())) { endpoint.locations(locationList); } if (!(languageList == null || languageList.isEmpty())) { endpoint.languages(languageList); } if ((customerKey != null && !customerKey.isEmpty()) && (customerSecret != null && !customerSecret.isEmpty()) && (token != null && !token.isEmpty()) && (tokenSecret != null && !tokenSecret.isEmpty())) { auth = new OAuth1(customerKey, customerSecret, token, tokenSecret); } else { auth = new OAuth1(TwitterUtils.twitterConstant.consumerKey, TwitterUtils.twitterConstant.consumerSecret, TwitterUtils.twitterConstant.token, TwitterUtils.twitterConstant.tokenSecret); } //BasicClient sets up connection to twitter with declaration on hostname to connect to, endpoint with trackTerms, authentication information and processor to process client events. twitterClient = new ClientBuilder() .hosts(Constants.STREAM_HOST) .endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(messageQueue)) .build(); }
.authentication(auth) .endpoint(endpoint) .processor(new StringDelimitedProcessor(msgQueue));
@PostConstruct public void init() { BlockingQueue<String> queue = new LinkedBlockingQueue<>(100); StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(); endpoint.trackTerms(ImmutableList.of("ExtJS", "#extjs", "Sencha", "#java", "java8", "java9", "#websocket", "#SpringFramework", "html5", "javascript", "#kotlin", "kotlin")); endpoint.languages(ImmutableList.of("en", "de")); String consumerKey = this.environment.getProperty("twitter4j.oauth.consumerKey"); String consumerSecret = this.environment .getProperty("twitter4j.oauth.consumerSecret"); String accessToken = this.environment.getProperty("twitter4j.oauth.accessToken"); String accessTokenSecret = this.environment .getProperty("twitter4j.oauth.accessTokenSecret"); Authentication auth = new OAuth1(consumerKey, consumerSecret, accessToken, accessTokenSecret); this.client = new ClientBuilder().hosts(Constants.STREAM_HOST).endpoint(endpoint) .authentication(auth).processor(new StringDelimitedProcessor(queue)) .build(); this.executorService = Executors.newSingleThreadExecutor(); TwitterStatusListener statusListener = new TwitterStatusListener( this.messagingTemplate, this.lastTweets); this.t4jClient = new Twitter4jStatusClient(this.client, queue, ImmutableList.of(statusListener), this.executorService); this.t4jClient.connect(); this.t4jClient.process(); }
.processor(new StringDelimitedProcessor(queue)).build();
@Override protected void init(@Nonnull Context context) { StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(); endpoint.trackTerms(terms); String consumerKey = properties.getProperty("consumerKey"); String consumerSecret = properties.getProperty("consumerSecret"); String token = properties.getProperty("token"); String tokenSecret = properties.getProperty("tokenSecret"); if (isMissing(consumerKey) || isMissing(consumerSecret) || isMissing(token) || isMissing(tokenSecret)) { throw new IllegalArgumentException("Twitter credentials are missing!"); } Authentication auth = new OAuth1(consumerKey, consumerSecret, token, tokenSecret); client = new ClientBuilder() .hosts(Constants.STREAM_HOST) .endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(queue)) .build(); client.connect(); }
TwitterSource(Properties properties, List<String> terms) { StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint().trackTerms(terms); String consumerKey = properties.getProperty("consumerKey"); String consumerSecret = properties.getProperty("consumerSecret"); String token = properties.getProperty("token"); String tokenSecret = properties.getProperty("tokenSecret"); if (isMissing(consumerKey) || isMissing(consumerSecret) || isMissing(token) || isMissing(tokenSecret)) { throw new IllegalArgumentException("Twitter credentials are missing!"); } Authentication auth = new OAuth1(consumerKey, consumerSecret, token, tokenSecret); client = new ClientBuilder() .hosts(Constants.STREAM_HOST) .endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(queue)) .build(); client.connect(); }
.authentication(hosebirdAuth) .endpoint(hosebirdEndpoint) .processor(new StringDelimitedProcessor(msgQueue));
public void run() throws InterruptedException, ControlStreamException, IOException { // Create an appropriately sized blocking queue final BlockingQueue<String> queue = new LinkedBlockingQueue<String>(10000); final UserstreamEndpoint endpoint = new UserstreamEndpoint(); final Authentication auth = new OAuth1(consumerKey, consumerSecret, accessToken, accessTokenSecret); // Create a new BasicClient. By default gzip is enabled. final BasicClient client = new ClientBuilder() .hosts(Constants.SITESTREAM_HOST) .endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(queue)) .build(); // Create an executor service which will spawn threads to do the actual work of parsing the incoming messages and // calling the listeners on each message final int numProcessingThreads = 4; final ExecutorService service = Executors.newFixedThreadPool(numProcessingThreads); // Wrap our BasicClient with the twitter4j client t4jClient = new Twitter4jUserstreamClient( client, queue, Lists.newArrayList(listener), service); // Establish a connection t4jClient.connect(); for (int threads = 0; threads < numProcessingThreads; threads++) { // This must be called once per processing thread t4jClient.process(); } }
.authentication(oauth) .eventMessageQueue(eventQueue) .processor(new StringDelimitedProcessor(messageQueue));
public Client createTwitterClient(BlockingQueue<String> msgQueue){ /** Declare the host you want to connect to, the endpoint, and authentication (basic auth or oauth) */ Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST); StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint(); hosebirdEndpoint.trackTerms(terms); // These secrets should be read from a config file Authentication hosebirdAuth = new OAuth1(consumerKey, consumerSecret, token, secret); ClientBuilder builder = new ClientBuilder() .name("Hosebird-Client-01") // optional: mainly for the logs .hosts(hosebirdHosts) .authentication(hosebirdAuth) .endpoint(hosebirdEndpoint) .processor(new StringDelimitedProcessor(msgQueue)); Client hosebirdClient = builder.build(); return hosebirdClient; }