Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message: Thread is already running . #2

Closed
irudrasingh opened this issue Apr 21, 2020 · 1 comment
Closed

Error message: Thread is already running . #2

irudrasingh opened this issue Apr 21, 2020 · 1 comment

Comments

@irudrasingh
Copy link

package twitter.kafka;

import com.google.common.collect.Lists;
import com.twitter.hbc.ClientBuilder;
import com.twitter.hbc.core.Client;
import com.twitter.hbc.core.Constants;
import com.twitter.hbc.core.Hosts;
import com.twitter.hbc.core.HttpHosts;
import com.twitter.hbc.core.endpoint.StatusesFilterEndpoint;
import com.twitter.hbc.core.processor.StringDelimitedProcessor;
import com.twitter.hbc.httpclient.auth.Authentication;
import com.twitter.hbc.httpclient.auth.OAuth1;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

public class TwitterProducer {

org.slf4j.Logger logger=LoggerFactory.getLogger(TwitterProducer.class.getName());

public static void main(String[] args) {
new TwitterProducer().run();
}

public void run(){
    /** Set up your blocking queues: Be sure to size these properly based on expected TPS of your stream */
    BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>(1000);


    Client client=createTwitterClient(msgQueue);
client.connect();
//loop to send tweets
    while (!client.isDone()) {
        String msg = null;
        try {
            msg = msgQueue.poll(5, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
            client.stop();
        }
        if(msg !=null)
        {
        logger.info(msg);
        }
        logger.info("Exit\n");
    }
}

String ConsumerKey="l5FqN7hy1EsY2SgUJhnkqhmw9";
String ConsumerSecret="LZJ48jU5oTtYnnW4rLqlyAr0xOvDEyizPjsrXDoKkKeHfG7t34";
String token="733920087296507908-7vE4BiMe8xnjT7L0GMMh38x0EFjyItO";
String secret="Z99utconKnWkPX2Hxcp6wxEKnvBXANlSVymk8E3BIZaWF";
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();
    // Optional: set up some followings and track terms
    List<String> terms = Lists.newArrayList("Palghar");
    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("HoseBirdClient-01")                              // optional: mainly for the logs
            .hosts(hosebirdHosts)
            .authentication(hosebirdAuth)
            .endpoint(hosebirdEndpoint)
            .processor(new StringDelimitedProcessor(msgQueue));                          // optional: use this if you want to process client events

    Client hosebirdClient = builder.build();

// Attempts to establish a connection.
hosebirdClient.connect();
return hosebirdClient;
}
}

Error:-
"C:\Program Files\Java\jdk1.8.0_221\bin\java" "-javaagent:D:\123\IntelliJ IDEA 2017.2.2\lib\idea_rt.jar=51166:D:\123\IntelliJ IDEA 2017.2.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_221\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_221\jre\lib\rt.jar;D:\Study Material only\kafka\project\target\classes;C:\Users\rudra.m2\repository\org\apache\kafka\kafka-clients\2.5.0\kafka-clients-2.5.0.jar;C:\Users\rudra.m2\repository\com\github\luben\zstd-jni\1.4.4-7\zstd-jni-1.4.4-7.jar;C:\Users\rudra.m2\repository\org\lz4\lz4-java\1.7.1\lz4-java-1.7.1.jar;C:\Users\rudra.m2\repository\org\xerial\snappy\snappy-java\1.1.7.3\snappy-java-1.1.7.3.jar;C:\Users\rudra.m2\repository\org\slf4j\slf4j-simple\1.7.21\slf4j-simple-1.7.21.jar;C:\Users\rudra.m2\repository\org\apache\logging\log4j\log4j-slf4j-impl\2.11.2\log4j-slf4j-impl-2.11.2.jar;C:\Users\rudra.m2\repository\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;C:\Users\rudra.m2\repository\org\apache\logging\log4j\log4j-core\2.11.2\log4j-core-2.11.2.jar;C:\Users\rudra.m2\repository\org\slf4j\slf4j-api\1.6.4\slf4j-api-1.6.4.jar;C:\Users\rudra.m2\repository\org\apache\cassandra\cassandra-all\0.8.1\cassandra-all-0.8.1.jar;C:\Users\rudra.m2\repository\com\google\guava\guava\r08\guava-r08.jar;C:\Users\rudra.m2\repository\commons-cli\commons-cli\1.1\commons-cli-1.1.jar;C:\Users\rudra.m2\repository\commons-codec\commons-codec\1.2\commons-codec-1.2.jar;C:\Users\rudra.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar;C:\Users\rudra.m2\repository\commons-lang\commons-lang\2.4\commons-lang-2.4.jar;C:\Users\rudra.m2\repository\com\googlecode\concurrentlinkedhashmap\concurrentlinkedhashmap-lru\1.1\concurrentlinkedhashmap-lru-1.1.jar;C:\Users\rudra.m2\repository\org\antlr\antlr\3.2\antlr-3.2.jar;C:\Users\rudra.m2\repository\org\antlr\antlr-runtime\3.2\antlr-runtime-3.2.jar;C:\Users\rudra.m2\repository\org\antlr\stringtemplate\3.2\stringtemplate-3.2.jar;C:\Users\rudra.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;C:\Users\rudra.m2\repository\org\apache\cassandra\deps\avro\1.4.0-cassandra-1\avro-1.4.0-cassandra-1.jar;C:\Users\rudra.m2\repository\org\mortbay\jetty\jetty\6.1.22\jetty-6.1.22.jar;C:\Users\rudra.m2\repository\org\mortbay\jetty\jetty-util\6.1.22\jetty-util-6.1.22.jar;C:\Users\rudra.m2\repository\org\mortbay\jetty\servlet-api\2.5-20081211\servlet-api-2.5-20081211.jar;C:\Users\rudra.m2\repository\org\codehaus\jackson\jackson-core-asl\1.4.0\jackson-core-asl-1.4.0.jar;C:\Users\rudra.m2\repository\org\codehaus\jackson\jackson-mapper-asl\1.4.0\jackson-mapper-asl-1.4.0.jar;C:\Users\rudra.m2\repository\jline\jline\0.9.94\jline-0.9.94.jar;C:\Users\rudra.m2\repository\com\googlecode\json-simple\json-simple\1.1\json-simple-1.1.jar;C:\Users\rudra.m2\repository\com\github\stephenc\high-scale-lib\high-scale-lib\1.1.2\high-scale-lib-1.1.2.jar;C:\Users\rudra.m2\repository\org\yaml\snakeyaml\1.6\snakeyaml-1.6.jar;C:\Users\rudra.m2\repository\org\apache\thrift\libthrift\0.6.1\libthrift-0.6.1.jar;C:\Users\rudra.m2\repository\junit\junit\4.4\junit-4.4.jar;C:\Users\rudra.m2\repository\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar;C:\Users\rudra.m2\repository\org\apache\cassandra\cassandra-thrift\0.8.1\cassandra-thrift-0.8.1.jar;C:\Users\rudra.m2\repository\com\github\stephenc\jamm\0.2.2\jamm-0.2.2.jar;C:\Users\rudra.m2\repository\com\twitter\hbc-core\2.2.0\hbc-core-2.2.0.jar;C:\Users\rudra.m2\repository\org\apache\httpcomponents\httpclient\4.2.5\httpclient-4.2.5.jar;C:\Users\rudra.m2\repository\org\apache\httpcomponents\httpcore\4.2.4\httpcore-4.2.4.jar;C:\Users\rudra.m2\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar;C:\Users\rudra.m2\repository\com\twitter\joauth\6.0.2\joauth-6.0.2.jar;C:\Users\rudra.m2\repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar" twitter.kafka.TwitterProducer
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/rudra/.m2/repository/org/slf4j/slf4j-simple/1.7.21/slf4j-simple-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/rudra/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.11.2/log4j-slf4j-impl-2.11.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
[main] INFO com.twitter.hbc.httpclient.BasicClient - New connection executed: HoseBirdClient-01, endpoint: /1.1/statuses/filter.json?delimited=length&stall_warnings=true
Exception in thread "main" java.lang.IllegalStateException: There is already a connection thread running for HoseBirdClient-01, endpoint: /1.1/statuses/filter.json?delimited=length&stall_warnings=true
at com.twitter.hbc.httpclient.BasicClient.connect(BasicClient.java:92)
at twitter.kafka.TwitterProducer.run(TwitterProducer.java:35)
at twitter.kafka.TwitterProducer.main(TwitterProducer.java:26)

Process finished with exit code 1

@winstonma
Copy link

winstonma commented Dec 2, 2020

Hi @irudrasingh I am studying on that Twitter chapter too. Unfortunately I didn't get approved for the Twitter developer account so I have to understand the whole chapter by watching it. I guess you are referring to TwitterProducer.java.

But as per my understanding the Hosebird Client (hbc) library stopped developing (last release: 2014) and they posted the below statement:

!! Note that, as of August 16th, 2018, the user streams and site streams features have been retired, so code that attempts to connect to these endpoints will no longer work.

Some people switched to Twitter4J. I am not sure if Twitter4J would solve the problem. Would like to see if @simplesteph would like to re-shoot several videos based on the using of Twitter4J.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants