如何修复在建立到的连接时捕获的kafka错误“ioexception”https://stream.twitter.com“在 java ?

0pizxfdo  于 2021-06-04  发布在  Kafka
关注(0)|答案(1)|浏览(363)

使用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

我正在尝试接收特定hashtag元素的流。我检查了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

尝试重新生成密钥和令牌。
下面是代码片段:

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\u主机是:

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

我希望连接建立起来,能够收到推特。流主机没有建立连接的原因是什么?

ggazkfy8

ggazkfy81#

谢谢那些看过我问题的人。
似乎这是由于我的笔记本电脑防火墙设置。我在另一台不太安全的笔记本电脑上尝试了完全相同的代码,效果很不错。需要和管理员商量一下。

相关问题