【问题标题】:How to fix a Kafka error "IOException caught when establishing connection to https://stream.twitter.com" in Java?如何在 Java 中修复 Kafka 错误“建立与 https://stream.twitter.com 的连接时捕获的 IOException”?
【发布时间】:2019-11-08 12:10:11
【问题描述】:

使用 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>
  1. 运行 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
  1. 并尝试重新生成密钥和令牌。

这是代码的sn-p:

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 twitter apache-kafka connection ioexception


    【解决方案1】:

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

    这似乎是由于我的笔记本电脑防火墙设置造成的。我用另一台不太安全的笔记本电脑尝试了完全相同的代码,它就像一个魅力。需要和管理员一起弄清楚。

    【讨论】:

    • 我遇到了同样的问题,你的评论解决了我的问题。
    • 我有一个 Symantec WSS 代理在后端工作。一旦我禁用它,我就能够接收推文。
    猜你喜欢
    • 2019-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-04-25
    相关资源
    最近更新 更多