java - 如何修复 Java 中的 Kafka 错误 "IOException caught when establishing connection to https://stream.twitter.com"?

标签 java twitter apache-kafka connection ioexception

使用 Kafka,我尝试将数据从 twitter 流式传输到 Java,但是当我运行该程序时,出现此错误:

[hosebird-client-io-thread-0] WARN com.twitter.hbc.httpclient.ClientBase - Hosebird-Client-01 IOException caught when establishing connection to https://stream.twitter.com/1.1/statuses/filter.json?delimited=length&stall_warnings=true
[hosebird-client-io-thread-0] WARN com.twitter.hbc.httpclient.ClientBase - Hosebird-Client-01 failed to establish connection properly
[hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase - Hosebird-Client-01 Done processing, preparing to close connection
  1. 我正在尝试接收特定主题标签元素的流。我检查了 pom.xml 中的依赖关系
<dependency>
  <groupId>com.twitter</groupId>
  <artifactId>hbc-core</artifactId> 
  <version>2.2.0</version>
</dependency>
  • 运行curl命令,我收到以下消息:
  • $ curl -I https://stream.twitter.com
    HTTP/1.1 404 Not Found
    content-length: 0
    date: Wed, 26 Jun 2019 13:28:19 GMT
    server: tsa_a
    set-cookie: personalization_id="v1_HSs6Yj5MLa8Ct13KsRWj3A=="; Max-Age=63072000; Expires=Fri, 25 Jun 2021 13:28:19 GMT; Path=/; Domain=.twitter.com
    set-cookie: guest_id=v1%3A156155569958747022; Max-Age=63072000; Expires=Fri, 25 Jun 2021 13:28:19 GMT; Path=/; Domain=.twitter.com
    strict-transport-security: max-age=631138519
    x-connection-hash: 567cd8537e0e96252c2175e59d752883
    x-response-time: 2
    
  • 并尝试重新生成 key 和 token 。
  • 这是代码片段:

    public void run(){
    
    // Setting blocking queues
    BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>(1000);
    
    // create a twitter client
    Client client = createTwitterClient(msgQueue);
    
    // Establish a connection.
    client.connect();
    
    // looping thru code
    // etc
    }
    
    public Client createTwitterClient(BlockingQueue<String> msgQueue){
    
    // Declared the keys and tokens
    
    // Host to connect to, the endpoint, and authentication (basic auth or oauth) */
    
    Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST); <- this guy
    StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();
    
    // rest of the code for ClientBuilder and Client
    }
    

    Constants.STREAM_HOST 的位置:

    public static final String STREAM_HOST = "https://stream.twitter.com";
    

    我希望连接能够建立并能够接收推文。 STREAM_HOST 未建立连接的原因是什么?

    最佳答案

    感谢那些阅读我的问题的人。

    这似乎是由于我的笔记本电脑防火墙设置而发生的。我在另一台安全性较低的笔记本电脑上尝试了完全相同的代码,它的工作原理非常神奇。需要与管理员弄清楚。

    关于java - 如何修复 Java 中的 Kafka 错误 "IOException caught when establishing connection to https://stream.twitter.com"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56774628/

    相关文章:

    c# - 将 C# RSACryptoServiceProvider 转换为 JAVA 代码

    php - 使用 CodeBird (PHP) 发布推文时使用短网址

    java - Android Twitter 应用程序无法从 Json 响应创建对象

    apache-kafka - 如果我将 log.segment.delete.delay.ms 设置为 0,我可以破坏任何东西吗

    apache-kafka - Zookeeper/Kafka 与 Tomcat - 可能吗?

    通过命令行使用 Junit 和 Jacoco,java 覆盖率为 0%

    java - 如何添加Java多线程

    c# - Twitter API + OAuth : Can't send status updates, 获取 401

    node.js - kafka Node 无法在本地环境中连接到kafka服务器

    java - 继承问题/问题